gpt4 book ai didi

python - 为什么我不能让 Python 的 urlopen() 方法在 Windows 上运行?

转载 作者:太空狗 更新时间:2023-10-29 22:28:11 24 4
gpt4 key购买 nike

为什么这个简单的 Python 代码不起作用?

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

这是我得到的错误:

Traceback (most recent call last):
File "C:\workspace\GarchUpdate\src\Practice.py", line 26, in <module>
file = urllib.urlopen('http://www.google.com')
File "C:\Python26\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python26\lib\urllib.py", line 206, in open
return getattr(self, name)(url)
File "C:\Python26\lib\urllib.py", line 345, in open_http
h.endheaders()
File "C:\Python26\lib\httplib.py", line 892, in endheaders
self._send_output()
File "C:\Python26\lib\httplib.py", line 764, in _send_output
self.send(msg)
File "C:\Python26\lib\httplib.py", line 723, in send
self.connect()
File "C:\Python26\lib\httplib.py", line 704, in connect
self.timeout)
File "C:\Python26\lib\socket.py", line 514, in create_connection
raise error, msg
IOError: [Errno socket error] [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

我已经在几个不同的页面上尝试过,但我永远无法让 urlopen 方法正确执行。

最佳答案

您的代码不是这里的问题。

您的 IE 中是否有任何代理设置?

这是 urllib.urlopen 的 python 文档:

In a Windows environment, if no proxy environment variables are set,
proxy settings are obtained from the registry's Internet Settings
section.

关于python - 为什么我不能让 Python 的 urlopen() 方法在 Windows 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2923703/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com