gpt4 book ai didi

Python urllib2 URLError 异常?

转载 作者:太空宇宙 更新时间:2023-11-04 07:04:31 26 4
gpt4 key购买 nike

我之前在 Windows XP 机器上安装了 Python 2.6.2 并运行以下代码:

import urllib2
import urllib

page = urllib2.Request('http://www.python.org/fish.html')
urllib2.urlopen( page )

我收到以下错误。

Traceback (most recent call last):<br>
File "C:\Python26\test3.py", line 6, in <module><br>
urllib2.urlopen( page )<br>
File "C:\Python26\lib\urllib2.py", line 124, in urlopen<br>
return _opener.open(url, data, timeout)<br>
File "C:\Python26\lib\urllib2.py", line 383, in open<br>
response = self._open(req, data)<br>
File "C:\Python26\lib\urllib2.py", line 401, in _open<br>
'_open', req)<br>
File "C:\Python26\lib\urllib2.py", line 361, in _call_chain<br>
result = func(*args)<br>
File "C:\Python26\lib\urllib2.py", line 1130, in http_open<br>
return self.do_open(httplib.HTTPConnection, req)<br>
File "C:\Python26\lib\urllib2.py", line 1105, in do_open<br>
raise URLError(err)<br>
URLError: <urlopen error [Errno 11001] getaddrinfo failed><br><br><br>

最佳答案

import urllib2
response = urllib2.urlopen('http://www.python.org/fish.html')
html = response.read()

你做错了。

关于Python urllib2 URLError 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1290142/

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