英文:
"getaddrinfo() argument 1 must be string or None" error starting dev_appserver.py on Linux
问题
我很久没有使用App Engine了,现在重新开始使用。我正在使用64位的Linux Go运行时,版本为1.8.1。
我相信我按照文档中的步骤正确操作,并且我相信我过去做过的事情是正确的,但是当我尝试启动dev_appserver.py
时,我遇到了这个错误:
<pre>
$ dev_appserver.py .
INFO 2013-07-11 07:24:45,919 sdk_update_checker.py:244] 检查SDK是否有更新。
INFO 2013-07-11 07:24:46,230 sdk_update_checker.py:288] 此SDK版本比宣传的版本更新。
WARNING 2013-07-11 07:24:46,443 simple_search_stub.py:955] 无法从/tmp/appengine.batterybotinfo.darshan/search_indexes读取搜索索引
Traceback (most recent call last):
File "/home/darshan/bin/dev_appserver.py", line 182, in <module>
_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 <module>
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()的第一个参数必须是字符串或None
</pre>
我最初的想法是可能我使用了错误版本的Python。果然,我使用的是2.7.5版本,而文档明确说明需要使用2.5版本。然而,文档似乎已经过时了,因为安装了2.5并设置系统使用它后,我得到了这个错误:
<pre>
错误:不支持Python 2.5。请使用2.7版本。
</pre>
好吧,回到2.7.5和我最初的错误。
我不确定这是否是dev_appserver.py
Python代码中的错误(我猜不是,因为它已经发布了一个月),还是我的Python安装有问题,或者我的系统配置不符合Google的期望。
除非必要,我不想修改dev_appserver.py
代码,但我很乐意尝试解决问题。错误出现在第194行;以下是第190-195行的代码:
<!-- language: lang-python -->
# AF_INET或AF_INET6套接字
# 获取我们主机的正确地址族(允许IPv6地址)
host, port = self.bind_addr
try:
info = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
我已经确定包含该方法被调用了两次。第一次host
始终为"127.0.0.1"
,port
为0
。第二次是导致崩溃的那次;host
始终为10
(一个整数,而不是字符串),port
是一个看似随机的五位数整数。
我尝试将host
硬编码为"127.0.0.1"
,port
为8080
或0
,但是然后我又得到了另一个错误。我感到有些力不从心,我怀疑通过改变我不太理解的东西来解决真正的问题。在Google上搜索错误消息也没有帮助。
英文:
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
:
<pre>
$ 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 <module>
_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 <module>
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
</pre>
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:
<pre>
Error: Python 2.5 is not supported. Please use version 2.7.
</pre>
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:
<!-- language: lang-python -->
# 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.
答案1
得分: 10
持续的谷歌搜索最终有了结果。尽管这个问题有一个非常不同(并且更具信息性)的错误信息,但解决方案却是相同的:确保/etc/hosts
文件只包含一个localhost
的条目。
值得注意的是,我的系统包含了这两行:
<!-- language: lang-conf -->
127.0.0.1 localhost
::1 localhost
注释掉第二行(并添加一条注释来说明原因)解决了我的问题:
<!-- language: lang-conf -->
127.0.0.1 localhost
# 有多个localhost条目会导致App Engine dev_appserver.py失败。
# 当前不需要IPv6,而开发服务器是需要的,所以注释掉。
#::1 localhost
dev_appserver.py
现在可以正常启动和工作了。
英文:
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:
<!-- language: lang-conf -->
127.0.0.1 localhost
::1 localhost
Commenting out the second (and adding a comment to document why) solved my issue:
<!-- language: lang-conf -->
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.
答案2
得分: 0
如果你将189-194行编辑为以下内容,它应该在Google发布更新之前可以工作。这基本上只是检查host
的类型,如果它不是字符串,则提前返回。
189 # AF_INET或AF_INET6套接字
190 # 获取我们主机的正确地址族(允许IPv6地址)
191 host, port = self.bind_addr
192 try:
193 if type(host) is not str:
194 return
195 info = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
196 socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
英文:
If you edit lines 189-194 to this, it should work until Google releases an update. This is basically just checking the type of host
and returning early if it isn't a string.
189 # AF_INET or AF_INET6 socket
190 # Get the correct address family for our host (allows IPv6 addresses)
191 host, port = self.bind_addr
192 try:
193 if type(host) is not str:
194 return
195 info = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
196 socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论