简体   繁体   English

学习 python 时的障碍 - Urlopen 错误 10060

[英]Roadblock while learning python - Urlopen error 10060

I'm trying to learn Python further but I've hit a roadblock.我正在尝试进一步学习 Python,但遇到了障碍。 I can't get urllib2/urllib working properly.我无法让 urllib2/urllib 正常工作。 If I do this response = urllib2.urlopen('http://python.org/') I get this error:如果我做这个response = urllib2.urlopen('http://python.org/')我得到这个错误:

    Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    response = urllib2.urlopen('http://python.org/')
  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>

Even something like URL = "http://173.194.75.94" followed by f=urllib.urlopen(URL) gives the same error, so it's not a DNS issue.甚至像URL = "http://173.194.75.94"后跟f=urllib.urlopen(URL)给出同样的错误,所以这不是 DNS 问题。 I'm behind no proxies or firewalls.我没有代理或防火墙。 Except my windows default firewall, which is disabled like it always has been.除了我的 Windows 默认防火墙,它像往常一样被禁用。 Even so I added python and pythonw.exe to it's exceptions.即便如此,我还是将 python 和 pythonw.exe 添加到它的例外中。

Any clue how to solve this?任何线索如何解决这个问题?

Using requests can make your life a lot easier;使用请求可以让你的生活更轻松;

In [1]: import requests

In [2]: pysite = requests.get('http://python.org/')

In [3]: pysite.status_code
Out[3]: 200

In [4]: pysite.ok
Out[4]: True

In [5]: pysite.text[0:40]
Out[5]: u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'

In [6]: pysite.error

In [7]: pysite.links
Out[7]: {}

In [8]: pysite.reason
Out[8]: 'OK'

You will still get exceptions when you try to go to a site that eg doesn't exist or is blocked on your network:当您尝试访问不存在或在您的网络上被阻止的站点时,您仍然会遇到异常:

In [3]: foobar = requests.get('http://foo.bar/')
---------------------------------------------------------------------------
ConnectionError                           Traceback (most recent call last)
<ipython-input-3-0917ff568fd4> in <module>()
----> 1 foobar = requests.get('http://foo.bar/')

/usr/local/lib/python2.7/site-packages/requests-0.14.1-py2.7.egg/requests/api.pyc in get(url, **kwargs)
     63 
     64     kwargs.setdefault('allow_redirects', True)
---> 65     return request('get', url, **kwargs)
     66 
     67 

/usr/local/lib/python2.7/site-packages/requests-0.14.1-py2.7.egg/requests/safe_mode.pyc in wrapped(method, url, **kwargs)
     37                 r.status_code = 0  # with this status_code, content returns None
     38                 return r
---> 39         return function(method, url, **kwargs)
     40     return wrapped

/usr/local/lib/python2.7/site-packages/requests-0.14.1-py2.7.egg/requests/api.pyc in request(method, url, **kwargs)
     49 
     50     try:
---> 51         return session.request(method=method, url=url, **kwargs)
     52     finally:
     53         if adhoc_session:

/usr/local/lib/python2.7/site-packages/requests-0.14.1-py2.7.egg/requests/sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, return_response, config, prefetch, verify, cert)
    239 
    240         # Send the HTTP Request.
--> 241         r.send(prefetch=prefetch)
    242 
    243         # Return the response.

/usr/local/lib/python2.7/site-packages/requests-0.14.1-py2.7.egg/requests/models.pyc in send(self, anyway, prefetch)
    629 
    630             except socket.error as sockerr:
--> 631                 raise ConnectionError(sockerr)
    632 
    633             except MaxRetryError as e:

ConnectionError: [Errno 8] hostname nor servname provided, or not known

But the information provided by the ConnectionError exception tells you what is going on;但是 ConnectionError 异常提供的信息告诉你发生了什么;

In [8]: try:                    
    foobar = requests.get('http://foo.bar/')
except requests.ConnectionError as oops:
    print oops.message
   ...:     
[Errno 8] hostname nor servname provided, or not known

Python:网址错误: <urlopen error [errno 10060]< div><div id="text_translate"><p> <strong>操作系统:Windows 7;</strong> <strong>Python 2.7.3 使用 Python GUI Shell</strong></p><p> 我正在尝试通过 Python 阅读一个网站,并且有几个作者使用urllib和urllib2库。 为了将站点存储在变量中,我看到了一种类似的方法:</p><pre> import urllib import urllib2 g = "http://www.google.com/" read = urllib2.urlopen(g)</pre><p> 最后一行在 120 多秒后生成错误:</p><pre> > 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></pre><p> 我尝试绕过g变量并尝试urlopen("http://www.google.com/")也没有成功(它在相同的时间长度后生成相同的错误)。</p></div></urlopen> - Python: URLError: <urlopen error [Errno 10060]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python urlopen 错误 [Errno 10060] - python urlopen error [Errno 10060] Python:网址错误: <urlopen error [errno 10060]< div><div id="text_translate"><p> <strong>操作系统:Windows 7;</strong> <strong>Python 2.7.3 使用 Python GUI Shell</strong></p><p> 我正在尝试通过 Python 阅读一个网站,并且有几个作者使用urllib和urllib2库。 为了将站点存储在变量中,我看到了一种类似的方法:</p><pre> import urllib import urllib2 g = "http://www.google.com/" read = urllib2.urlopen(g)</pre><p> 最后一行在 120 多秒后生成错误:</p><pre> > 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></pre><p> 我尝试绕过g变量并尝试urlopen("http://www.google.com/")也没有成功(它在相同的时间长度后生成相同的错误)。</p></div></urlopen> - Python: URLError: <urlopen error [Errno 10060] Python urlopen IOError:[Errno socket错误] [Errno 10060] - Python urlopen IOError: [Errno socket error] [Errno 10060] Python:urllib2.URLError: - Python: urllib2.URLError: <urlopen error [Errno 10060] 如何克服urlopen错误[WinError 10060]问题? - How to overcome urlopen error [WinError 10060] issue? urllib.error.URLError: - urllib.error.URLError: <urlopen error [WinError 10060] using urllib.request.urlretrieve() on Windows 10 with Python3 Python请求错误10060 - Python requests error 10060 socket.error:[Errno 10060]使用Python发送电子邮件时 - socket.error: [Errno 10060] while sending an email with Python Python gspread登录错误10060 - Python gspread login error 10060 Python smtplib连接错误10060 - Python smtplib connect error 10060
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM