Python:URLError:<urlopen 错误 [Errno 10060] [英] Python: URLError: <urlopen error [Errno 10060]

查看:59
本文介绍了Python:URLError:<urlopen 错误 [Errno 10060]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统:Windows 7;使用 Python GUI Shell 的 Python 2.7.3

我正在尝试通过 Python 读取网站,并且有几位作者使用了 urlliburllib2 库.要将站点存储在变量中,我已经看到了类似的方法建议:

I'm trying to read a website through Python, and several authors use the urllib and urllib2 libraries. To store the site in a variable, I've seen a similar approach proposed:

import urllib
import urllib2
g = "http://www.google.com/"
read = urllib2.urlopen(g)

最后一行在超过 120 秒后产生错误:

The last line generates an error after a 120+ seconds:

> Traceback (most recent call last):   File "<pyshell#27>", line 1, in
> <module>
>     r = urllib2.urlopen(o)   File "C:\Python27\lib\urllib2.py", line 126, in urlopen
>     return _opener.open(url, data, timeout)   File "C:\Python27\lib\urllib2.py", line 400, in open
>     response = self._open(req, data)   File "C:\Python27\lib\urllib2.py", line 418, in _open
>     '_open', req)   File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
>     result = func(*args)   File "C:\Python27\lib\urllib2.py", line 1207, in http_open
>     return self.do_open(httplib.HTTPConnection, req)   File "C:\Python27\lib\urllib2.py", line 1177, in do_open
>     raise URLError(err) URLError: <urlopen 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>

我尝试绕过 g 变量并尝试 urlopen("http://www.google.com/") 也没有成功(它生成相同的相同时间后出错).

I tried bypassing the g variable and trying to urlopen("http://www.google.com/") with no success either (it generates the same error after the same length of time).

推荐答案

错误代码 10060 表示无法连接到远程对等点.这可能是因为网络问题,或者主要是您的设置问题,例如代理设置.

The error code 10060 means it cannot connect to the remote peer. It might be because of the network problem or mostly your setting issues, such as proxy setting.

您可以尝试将同一台主机与其他工具(例如 ncat)和/或同一本地网络中的另一台 PC 连接,以找出问题发生的位置.

You could try to connect the same host with other tools(such as ncat) and/or with another PC within your same local network to find out where the problem is occuring.

关于代理问题,这里有一些材料:

For proxy issue, there are some material here:

使用 HTTP 代理 - Python

为什么我获取不到 Python 的 urlopen() 方法在 Windows 上工作?

希望有帮助!

这篇关于Python:URLError:&lt;urlopen 错误 [Errno 10060]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆