"getaddrinfo() argument 1 must be string or None" error starting dev_appserver.py on Linux

15,930

Persistent Googling eventually paid off. Despite this question having a very different (and much more informative) error message, the solution turned out to be the same: ensure that /etc/hosts contains only a single entry for localhost.

Notably, my system contained both of these lines:

127.0.0.1  localhost
::1        localhost

Commenting out the second (and adding a comment to document why) solved my issue:

127.0.0.1  localhost

# Having multiple localhost entries causes App Enginge dev_appserver.py to fail.
#  IPv6 not currently needed, and the dev server IS needed, so commenting out.
#::1        localhost

dev_appserver.py now starts and works properly.

Share:
15,930
Darshan Rivka Whittle
Author by

Darshan Rivka Whittle

Updated on June 04, 2022

Comments

  • Darshan Rivka Whittle
    Darshan Rivka Whittle almost 2 years

    I'm getting re-started with App Engine after not having used it in a while. I'm using the 64-bit Linux Go runtime, version 1.8.1.

    I believe I'm following the steps from the documentation correctly, and I believe I'm doing what's worked correctly in the past, but I'm getting this error when attempting to launch dev_appserver.py:

    $ dev_appserver.py .
    INFO     2013-07-11 07:24:45,919 sdk_update_checker.py:244] Checking for updates to the SDK.
    INFO     2013-07-11 07:24:46,230 sdk_update_checker.py:288] This SDK release is newer than the advertised release.
    WARNING  2013-07-11 07:24:46,443 simple_search_stub.py:955] Could not read search indexes from /tmp/appengine.batterybotinfo.darshan/search_indexes
    Traceback (most recent call last):
      File "/home/darshan/bin/dev_appserver.py", line 182, in 
        _run_file(__file__, globals())
      File "/home/darshan/bin/dev_appserver.py", line 178, in _run_file
        execfile(script_path, globals_)
      File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 695, in 
        main()
      File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 688, in main
        dev_server.start(options)
      File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 659, in start
        apis.start()
      File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 137, in start
        super(APIServer, self).start()
      File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 295, in start
        if self._start_all_dynamic_port(host_ports):
      File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 348, in _start_all_dynamic_port
        server.start()
      File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 194, in start
        socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
    TypeError: getaddrinfo() argument 1 must be string or None
    

    My first thought was that I might be using an incorrect version of Python. Sure enough, I'm using 2.7.5, and the documentation clearly states that 2.5 is necessary. However, the documentation seems to be outdated, because after installing 2.5 and setting my system to use it, I got this error:

    Error: Python 2.5 is not supported. Please use version 2.7.
    

    Okay, so back to 2.7.5 and my initial error.

    I'm not sure if this is a bug in the dev_appserver.py Python code (I'm guessing not, as it's been out for a month), an issue with my Python installation, or something else about my system that isn't configured according to Google's expectations.

    I'd rather not mess with the dev_appserver.py code unless necessary, but I'm happy to poke at it to help figure out what's going wrong. The error is on line 194; here are lines 190-195:

    # AF_INET or AF_INET6 socket
    # Get the correct address family for our host (allows IPv6 addresses)
    host, port = self.bind_addr
    try:
      info = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
                                socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
    

    I've determined that the containing method is called twice. The first time host is always "127.0.0.1" and port is 0. The second time is the one that crashes; host is always 10 (an int, not a string), and port is a seemingly-random five-digit int.

    I've tried hard-coding host to "127.0.0.1" and port to either 8080 or 0, but then I get another error. I feel in over my head, and I suspect I'm not going to resolve the real issue by changing things I don't really understand. Googling for the error message hasn't helped.