如何在Windows上修复Python的getaddrinfo失败问题

3
如果我在命令提示终端中启动Python并尝试打开某个URL,尽管该名称可以通过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考虑了这个设置,从而导致了错误。


3
值得注意的是,对于我们这些不习惯微软方式的人来说,Internet Explorer的设置也会影响其他程序。代理设置,至少在Windows Server 2012中,被隐藏在Internet Explorer → ⚙ → 工具 → Internet选项 → 连接 → LAN设置下。(在任何苹果用户开始吹嘘之前,至少这些步骤都标有字符,而不是在Mac世界中显然具有意义的漂亮彩色旋钮。) - Michael Scheper

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接