Python-Urllib2:[Errno 54]连接由同行重置

时间:2018-02-01 23:50:53

标签: python python-2.7 urllib2 pyopenssl

使用Urllib2时出现以下错误:

[Errno 54]通过对等方重置连接

以下是代码:

import urllib2   
url = "https://api.thousandeyes.com/";
response = urllib2.urlopen(url, context=ctx);

这是错误:

nnayar$ python test2.py
OpenSSL 0.9.8zh 14 Jan 2016
Traceback (most recent call last):
  File "test2.py", line 13, in <module>
    response = urllib2.urlopen(url);
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
    '_open', req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
    context=self._context)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 54] Connection reset by peer>

如何解决此问题?

1 个答案:

答案 0 :(得分:3)

API最近弃用了导致此问题的TLS 1.0支持。我现在正在努力升级python以使用TLS1.2,这也非常具有挑战性,因为Mac的默认安装只支持TLS 1.0。