且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google App Engine&的urllib错误python。[Errno 11003] getaddrinfo失败

更新时间:2022-12-01 09:03:24

您的系统不一定知道本地主机应该解析为127.0.0.1。您可能需要将条目放入主机文件中。在Windows上,它位于 C:\Windows\System32\drivers\etc\hosts


Thanks for your help in advance!

I want to get contents of a website, so I use urllib.urlopen(url).

set url='http://localhost:8080'(tomcat page)

If I use Google App Engine Launcher, run the application, browse http://localhost:8082 , it works well. But if I specify the address and port for the application:

python `"D:\Program Files\Google\google_appengine\dev_appserver.py" -p 8082 -a 10.96.72.213 D:\pagedemon\videoareademo`

there's something wrong:

Traceback (most recent call last):
File "D:\Program Files\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 701, in __call__
  handler.get(*groups)
File "D:\pagedemon\videoareademo\home.py", line 76, in get
  wp = urllib.urlopen(url)
File "C:\Python27\lib\urllib.py", line 84, in urlopen
  return opener.open(url)
File "C:\Python27\lib\urllib.py", line 205, in open
  return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 343, in open_http
  errcode, errmsg, headers = h.getreply()
File "D:\Program Files\Google\google_appengine\google\appengine\dist\httplib.py", line 334, in getreply
  response = self._conn.getresponse()
File "D:\Program Files\Google\google_appengine\google\appengine\dist\httplib.py", line 222, in getresponse
  deadline=self.timeout)
File "D:\Program Files\Google\google_appengine\google\appengine\api\urlfetch.py", line 263, in fetch
  return rpc.get_result()
File "D:\Program Files\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 592, in get_result
  return self.__get_result_hook(self)
File "D:\Program Files\Google\google_appengine\google\appengine\api\urlfetch.py", line 365, in _get_fetch_result
  raise DownloadError(str(err))
DownloadError: ApplicationError: 2 [Errno 11003] getaddrinfo failed

The strangest thing is when I change the url form "http://localhost:8080" to "http://127.0.0.1:8080", it works well!

I googled a lot, but I didn't find any good solutions.Hoping for some help! Also, I didn't configure any proxy.IE works well.

Your system doesn't necessarily know that localhost should resolve to 127.0.0.1. You might need to put an entry into your hosts file. On Windows, it's located at C:\Windows\System32\drivers\etc\hosts