Failed to start devlopment server — BindError: Unable to find a consistent port localhost

Failed to start devlopment server — BindError: Unable to find a consistent port localhost

Google-app-engine development server runs great yesterday, but when I try to start it today. It only shout out this Error. 
I tried use lsof -i:8080 / lsof -i:8000 to make sure these ports are not taken.
I also tried use a --port arg to switch to another port. 
I even removed the gae folder and installed a new one.
-- with no luck at all.
Maybe there is a obvious solution but I can't see it.
Here is the Oh-My-God trace stack..
Traceback (most recent call last):
File "/home/henry/software/google_appengine/", line 182, in 
        _run_file(__file__, globals())
File "/home/henry/software/google_appengine/", line 178, in _run_file
        execfile(script_path, globals_)
File "/home/henry/software/google_appengine/google/appengine/tools/devappserver2/", line 689, in 
File "/home/henry/software/google_appengine/google/appengine/tools/devappserver2/", line 682, in main
File "/home/henry/software/google_appengine/google/appengine/tools/devappserver2/", line 653, in start
File "/home/henry/software/google_appengine/google/appengine/tools/devappserver2/", line 152, in start
        super(APIServer, self).start()
File "/home/henry/software/google_appengine/google/appengine/tools/devappserver2/", line 294, in start
        raise BindError('Unable to find a consistent port %s' % host) Unable to find a consistent port localhost
    Exception in thread Thread-4 (most likely raised during interpreter shutdown):
    Traceback (most recent call last):
      File "/usr/lib/python2.7/", line 810, in __bootstrap_inner
      File "/usr/lib/python2.7/", line 763, in runhenry@henry-A


Answer 1:

This can be caused by multiple entries in your hosts file for ‘localhost’.

For example in file /etc/hosts: localhost mymachinename localhost

if you delete all mappings but one for localhost, the problem will hopefully be resolved. mymachinename localhost

This is a known issue and as far as I understand it will be corrected in a future release.

Answer 2:

While I never seen that before try running it on a different port or even using a different host: /path/to/project --port 8888 --host

Where for host add your current IP address.

Answer 3:

Similar to what was posted, I had this issue and fixed it by altering the hosts file. The issue was with IPv6 addresses redirecting to localhost:

In my hosts file I had    localhost
::1          localhost 
fe80::1%lo0  localhost

And I commented out the IPv6 addresses to give     localhost
#::1          localhost 
#fe80::1%lo0  localhost

I’m not sure this is a viable permanent solution as I imagine it’s important to have the IPv6 numerical addresses for localhost to be in the hosts file but it works for now until a proper fix is released.

Answer 4:

I suppose there is a bug in the google app engine.
I debuged appengine/tools/devappserver2/, and here is the facts:
1. it runs fine when internet is disconnected
2. it shows such error when internet is on.

280 addrinfo = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
281                                     socket.SOCK_STREAM, 0, socket.AI_PASSIVE)

In this piece of code, if you connect internet, addrinfo will only have the address in public internet. even you assign port and host in command line. Then you have no chance to bind this socket to localhost, since the address you bind is the public address you are using now.

In order to solve it, I just change the code into

280 addrinfo = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
281                                     socket.SOCK_STREAM, 1, socket.AI_PASSIVE)

It works well now, I didn’t check the code about socket.getaddrinfo, however, I suppose that it functions as ignoring the lookup address or not according to the integer 0 or 1.

Btw, I am using MacOs, there could be system dependency problem as well, if this is the case, then socket package should redesign somehow.

Answer 5: . --port 4000

this fixed it for me.

Answer 6:

I solved this issue by passing an explicit api port to path/to/project --api_port 3000

I was unable to solve the issue by editing the hosts file or passing --port / --host to

I didn’t identify the root cause.

Answer 7:

In my case just restarting the terminal worked.