Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot fetch URLs from GAE local environment

I'm getting the following error when trying to fetch an URL with urllib2 in the google app engine:

error: An error occured while connecting to the server: Unable to fetch URL: http://www.google.com Error: [Errno 10106] getaddrinfo failed

This is the code calling the urllib2 open read methods:

def get(self):
        self.write(urllib2.urlopen("http://www.google.com").read())
        self.render_index()

Nothing fancy, just a call to the library inside the main handler to ouptut the fetched text.

My PC resolves DNS correctly. I can use the urllib2 library from the python interpeter, fetching URLs successfully.

The deployed code running from the google servers work as intended, it's something with my local environment but I can't find what is it.

I also tried using urlfetch from gae with similar results (same getaddrinfo failed)

I switched to Google DNS some days before working with the urllib2 library but switching back to ISP provided DNS didn't work either.

EDIT: When calling the function with an IP address the URL is fetched:

self.write(urllib2.urlopen("http://173.194.42.34").read())

Thanks in advance!

like image 554
user2178715 Avatar asked Nov 04 '22 02:11

user2178715


1 Answers

I'm fairly certain that your DNS resolver fails to resolve the hostname. I assume that your OS, or security software prohibits the devserver from creating outbound connection. Another possibility would be that you have invalid entry in your hosts file on your operating system.

Also, there are many similar questions which could help you.

like image 113
Takashi Matsuo Avatar answered Nov 09 '22 23:11

Takashi Matsuo