Cannot connect to external services from the App Engine development server using urlfetch or urllib2

The following code works in the Python interactive shell:

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

and gives a result of 200.

If I ran the same code in an AppEngine application that works locally with a development server, it did not execute 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 tried using the urlfetch library urlfetch :

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

and this also fails (which makes sense since I believe urllib2 inside AppEngine calls urlfetch internally?)

I can access the url from my local machine - so what happens?

UPDATE: corresponding 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 
+4
source share
1 answer

Do you have a proxy configured with environment variables? Dev_appserver clears all env vars.

+1
source

Source: https://habr.com/ru/post/1435937/


All Articles