如何修复Windows上Python的getaddrinfo失败

3 投票
1 回答
9034 浏览
提问于 2025-04-17 10:37

如果我在命令提示符下启动Python,然后尝试打开某个网址,我会得到以下结果,尽管这个网址的名字可以通过DNS解析出来:

C:\Windows\system32>nslookup www.google.de
Nicht-autorisierende Antwort:
Name:    www-cctld.l.google.com
Address:  173.194.69.94
Aliases:  www.google.de
C:\Windows\system32>C:\Python27\python.exe
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> urllib.urlopen("http://www.google.de")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\urllib.py", line 84, in urlopen
    return opener.open(url)
  File "C:\Python27\lib\urllib.py", line 205, in open
    return getattr(self, name)(url)
  File "C:\Python27\lib\urllib.py", line 342, in open_http
    h.endheaders(data)
  File "C:\Python27\lib\httplib.py", line 951, in endheaders
    self._send_output(message_body)
  File "C:\Python27\lib\httplib.py", line 811, in _send_output
    self.send(msg)
  File "C:\Python27\lib\httplib.py", line 773, in send
    self.connect()
  File "C:\Python27\lib\httplib.py", line 754, in connect
    self.timeout, self.source_address)
  File "C:\Python27\lib\socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
IOError: [Errno socket error] [Errno 11001] getaddrinfo failed
>>>

我已经关闭了防火墙,并且以管理员身份启动了命令提示符,但我能想到的就这些。nslookup这个命令运行得很好,所以我不知道问题出在哪里。有没有什么建议?

1 个回答

1

看起来在Internet Explorer的连接设置中,定义了一个无法连接的代理。出于某种原因,urllib会考虑这个设置,因此导致了错误的发生。

撰写回答