Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to external services from App Engine development server with urlfetch or urllib2

The following code works in the Python interactive shell:

import urllib2
result = urllib2.urlopen("http://www.google.com/")

and gives a 200 result.

If I run the same code in an AppEngine app running locally with the development server, it fails with the following error:

URLError: <urlopen error An error occured while connecting to the server:
Unable to fetch  URL: http://www.google.com/ 
Error: [Errno 11004] getaddrinfo failed>`

I've tried using the urlfetch library directly:

from google.appengine.api import urlfetch
result = urlfetch.fetch("http://www.google.com")

and this also fails (which makes sense, as I believe urllib2 within AppEngine calls URLFetch internally?)

I can clearly access the URL from my local machine - so what's happening?

UPDATE: the relevant stack trace:

File "c:\dev\repos\stackoverflow\main.py", line 40, in get_latest_comments
result = urlfetch.fetch("http://www.google.com")

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py", line 266, in fetch
return rpc.get_result()

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 604, in get_result
return self.__get_result_hook(self)

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\urlfetch.py", line 397, in _get_fetch_result
raise DownloadError("Unable to fetch URL: " + url + error_detail)

DownloadError: Unable to fetch URL: http://www.google.com Error: [Errno 11004] getaddrinfo failed
like image 522
Hugo Rodger-Brown Avatar asked Nov 13 '22 21:11

Hugo Rodger-Brown


1 Answers

DO you have a proxy configured with environment variables? The dev_appserver clears all env vars.

like image 113
Guido van Rossum Avatar answered Nov 15 '22 10:11

Guido van Rossum