Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

urllib2.URLError: <urlopen error [Errno 11004] getaddrinfo failed>

Tags:

python

urllib2

If I run:

urllib2.urlopen('http://google.com')

even if I use another url, I get the same error.

I'm pretty sure there is no firewall running on my computer or router, and the internet (from a browser) works fine.

like image 916
quilby Avatar asked Feb 16 '11 22:02

quilby


2 Answers

The problem, in my case, was that some install at some point defined an environment variable http_proxy on my machine when I had no proxy.

Removing the http_proxy environment variable fixed the problem.

like image 102
Declan Brennan Avatar answered Sep 18 '22 17:09

Declan Brennan


The site's DNS record is such that Python fails the DNS lookup in a peculiar way: it finds the entry, but zero associated IP addresses. (Verify with nslookup.) Hence, 11004, WSANO_DATA.

Prefix the site with 'www.' and try the request again. (Use nslookup to verify that its result is different, too.)

This fails essentially the same way with the Python Requests module:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='...', port=80): Max retries exceeded with url: / (Caused by : [Errno 11004] getaddrinfo failed)

like image 22
JimB Avatar answered Sep 21 '22 17:09

JimB