Title: Apps won't run on GAE - 'unable to bind to localhost:0'
Tags: python;google-app-engine
Question: I recently upgraded Google App Engine to 1.7.7. and have not been able to run any apps locally since. This includes apps that worked before the update and apps I've created since. I haven't come across any other references to this specific problem 'Unable to bind to localhost:0,' so any insights into clearing this hurdle would be much appreciated.
I'm including the log for a new 'Hello World' app I added today. Using Python 2.7 via ActivePython on OS X 10.6.8.
*** Running dev_appserver with the following flags:
--skip_sdk_update_check=yes --port=12084 --admin_port=8007
Python command: /usr/local/bin/pythonw
INFO     2013-04-13 06:37:31,627 devappserver2.py:498] Skipping SDK update check.
WARNING  2013-04-13 06:37:31,691 api_server.py:328] Could not initialize images API; you are likely missing the Python "PIL" module.
WARNING  2013-04-13 06:37:31,692 simple_search_stub.py:977] Could not read search indexes from /var/folders/ag/ag25hkLMFEG1p0pLBBX5Mk+++TI/-Tmp-/appengine.binderror.b/search_indexes
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py", line 193, in <module&gt;
_run_file(__file__, globals())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py", line 189, in _run_file
execfile(script_path, globals_)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 662, in <module&gt;
main()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 655, in main
dev_server.start(options)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 626, in start
apis.start()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 151, in start
super(APIServer, self).start()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 296, in start
raise BindError('Unable to bind %s:%s' % self.bind_addr)
google.appengine.tools.devappserver2.wsgi_server.BindError: Unable to bind localhost:0
Update: I was able to deploy the 'Hello World' app through GAE Launcher without any issues. I ran the command errinfo -c -n GoogleAppEngineLauncher.app, which uses the included dtrace, and then attempted to run three apps, then closed them. Here is the output [which is somewhat beyond me]:
EXEC          SYSCALL  ERR  COUNT  DESC
GoogleAppEngine          madvise   12      1  Cannot allocate memory
GoogleAppEngine __disable_threadsignal    0      2
GoogleAppEngine           access    0      3
GoogleAppEngine bsdthread_register   22      3  Invalid argument
GoogleAppEngine            chdir    0      3
GoogleAppEngine   close_nocancel    0      3
GoogleAppEngine   fcntl_nocancel    0      3
GoogleAppEngine             fork    0      3
GoogleAppEngine    getdtablesize    0      3
GoogleAppEngine           getpid    0      3
GoogleAppEngine    open_nocancel    0      3
GoogleAppEngine           setsid    0      3
GoogleAppEngine      sigprocmask    0      3
GoogleAppEngine           stat64    0      3
GoogleAppEngine            wait4    0      3
GoogleAppEngine       workq_open    0      3
GoogleAppEngine            write    0      3
GoogleAppEngine          lstat64    0      4
GoogleAppEngine             pipe    0      6
GoogleAppEngine    thread_selfid    0      6
GoogleAppEngine     gettimeofday    0      7
GoogleAppEngine             dup2    0      9
GoogleAppEngine          madvise    0     17
GoogleAppEngine           munmap    0     31
GoogleAppEngine             mmap    0     33
GoogleAppEngine        sigaction    0     87
GoogleAppEngine      getattrlist    0    102
GoogleAppEngine          fstat64    0    118
GoogleAppEngine             open    0    118
GoogleAppEngine          geteuid    0    208
GoogleAppEngine              dup    0  10418
GoogleAppEngine             read    0  10532
GoogleAppEngine            close    0  10584
GoogleAppEngine workq_kernreturn    0  20752
GoogleAppEngine            close    9  21459  Bad file descriptor
GoogleAppEngine           kevent    0  72543
Update 2, 16 August: I installed the newest version of GAE Launcher [1.8.3] and everything now works.
Comment: how did you finally can run the helloworld app?

Comment: Try using `strace` to see what the actual `errno` from `bind` is, since GAE is too rude to print it out.

Comment: @BenJackson I'll (eventually) get `strace` installed & give that a shot - the tar.gz is giving me trouble right now.
@TimHoffman Unless I'm doing it wrong, nothing is listening on that port. I used the `lsof` command.

Comment: @Zyoo, I was able to use the Launcher to get the helloworld app to the Google App Engine servers and can view it live online. Still unable to test it locally.

Comment: You might also like to check and see if something is already listening on the ports you selected. Specicially 12084


Here is another answer: Had the same issue, was actually trying to run the server with the GUI too. Stopped it in the GUI, works perfectly.

Here is another answer: your socket is already in use. kill it and it should be resolved.fuser -k 8080/tcp
for example the above code kills and frees the socket at 8080
Comment for this answer: Had the same problem, this works for me. Also try closing any other running GAE local server, and any GAE admin console tab in your browser
Comment for this answer: Using `-k` for `fuser` gives me an error - system says that's not an option.

Here is another answer: The last time you ran the app engine command you shut it down with ctrl-z instead (shunt to background) instead of ctrl-c (kill). Restart the terminal and next time you shut down app engine from terminal use ctrl-c and you'll be fine.

Here is another answer: fuser -k command didn't work for me because of the unknown option and I did this instead.
See which process is using the port via "sudo lsof -i -n -P | grep TCP". I took note of the process ID and quit it via Activity Monitor (in the Network Tab).
Comment for this answer: Thank you for this. Worked perfectly.

Here is another answer: Ubuntu 14.04 has a lightweight server named "webfs" listening on localhost:8000. Run - sudo netstat -taupen | grep ":8000" - in a terminal to confirm. If it's listening run - sudo killall -q /usr/bin/webfsd - to kill it it. GAE uses ports 8000 and 8080 and won't start if one or both are busy.
On reflection, the webfs daemon can also be turned on and off as a service: sudo service webfs start/stop. However, as both methods require root privileges, they are not easy to automate.
As I start appengine locally from the command line, simply changing the admin port from 8000 to 8001 on startup proved a more considered approach. My command line looks like: google_appengine/dev_appserver.py --admin_port 8001 projects/helloworld/

Here is another answer: Test it in another port adding --port NUMBER when starting the server.
Comment for this answer: I attempted to use a different port number when starting the server, and received the same error.
Comment for this answer: Unfortunately, I get the same error, even running just one application. I think I'm going to have to uninstall this version, and reinstall an earlier one.
Comment for this answer: I have tried to run a few of them in the Terminal and get a variation on this error:
`Remnants:two-two-test b$ dev_appserver.py main.py
...raise yaml_errors.EventListenerYAMLError(e)
google.appengine.api.yaml_errors.EventListenerYAMLError: mapping values are not allowed here
in "main.py", line 35, column 22`
where line 35 is `def render(self, template, **kw):` and column 22 is the space between `self,` and `template`.
Comment for this answer: Are you running just one application with the appengine? If I run my app X and try to run an app Y, even in another port, it return me "google.appengine.tools.devappserver2.wsgi_server.BindError: Unable to bind localhost:8000".
Comment for this answer: Did you try to run just in the terminal without the Launcher?

Here is another answer: For people who got Unknown key when running fuser -k 8080/tcp, here is a solution which worked for me:
lsof -P | grep ':8080' | awk '{print $2}' | xargs kill -9
Comment for this answer: Did not work for me. I don't think it found anything when it did a grep.
Comment for this answer: This worked for me after the `fuser -k` command didn't! Thanks!

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 7, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:04/13/13', 'FavoriteCount': 6.0, 'PostTypeId': 1, 'Tags': '<python><google-app-engine>', 'Title': "Apps won't run on GAE - 'unable to bind to localhost:0'", 'ViewCount': 15667, 'id': 15985130, 'user_AboutMe': '<p>Software Engineer at OwnLocal, graduate of Carnegie Mellon University and Hack Reactor [neé MakerSquare]</p>\n', 'user_AccountId': 2630789.0, 'user_DisplayName': 'Yossarian', 'user_Reputation': 189.0, 'user_Views': 50.0, 'user_id': 2276791.0}}