简体   繁体   中英

getaddrinfo unable to resolve host

I'm having a weird problem. I have this Python application and when I try to open a url in the application, for instance urllib2.urlopen("http://google.com", None) I get the following error:

IOError: [Errno socket error] [Errno 8] nodename nor servname provided, or not known

However when I do the same thing on the python command line interpreter it works fine. The same python executable is being used for both the application and the command line.

nslookup google.com seems to work fine. I opened up wireshark and it looks like when the application tries to open google.com only a mDNS query goes out for "My-Name-MacBook-Pro.local" . However, when the command line tries to open google.com a regular DNS query goes out for "google.com" I found if I hardcoded Google's IP in /etc/hosts then the request from the application finally started working.

It seems something weird must be altering how the application resolves domain names, but I have no idea what could be doing this.

I'm running Mac OSX 10.6.7 and Python 2.6.

Edit : I am not using a proxy to access the internet

Just see that you don't have HTTP_PROXY environment variable set which is preventing this. (In which case, that would be a bad error message. Given the proper directory and try again, like

import urllib
r = urlib.urlopen('http://www.google.com')
print r.read()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM