-1
我正在構建一個使用GAE的簡單應用程序,該應用程序獲取一個URL並使用urllib2進行一些處理,如文檔中所述。urlopen GAE getaddrinfo錯誤()
import webapp2
import urllib2
class Handler(webapp2.RequestHandler):
def get(self):
url = "http://www.google.com/"
try:
result = urllib2.urlopen(url)
self.response.out.write(result)
except urllib2.URLError, e:
handleError(e)
app = webapp2.WSGIApplication([("/", Handler)], debug = True)
嘗試與urlfetch相同,但我不斷收到相同的錯誤。
如果我用IP地址調用urlopen(),它可以正常工作。
我認爲這可能是一個DNS問題,但從解釋器調用urllib2.urlopen("http://www.google.com")
正確解決。此外,我可以瀏覽和ping沒有問題。
問了一些朋友在我們的環境中試用這段代碼,結果是一樣的。
運行此相同代碼的已部署的應用程序工作得很好。
我想知道如果這可能是我的ISP的問題,因爲所有3次嘗試都是從不同的地方完成相同的ISP。
不,我不會通過代理,至少不是我配置的或我可以看到的一個。
這裏的堆棧跟蹤
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
return handler.dispatch()
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "C:\Users\Developer\Desktop\test\main.py", line 8, in get
result = urllib2.urlopen(url)
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 400, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 418, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1207, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1180, in do_open
r = h.getresponse(buffering=True)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\dist27\httplib.py", line 507, in getresponse
'An error occured while connecting to the server: %s' % e)
error: An error occured while connecting to the server: Unable to fetch URL: http://www.google.com/ Error: [Errno 10106] getaddrinfo failed