Getting the following error when using Urllib2:
[Errno 54] Connection reset by peer
Here is the code:
import urllib2
url = "https://api.thousandeyes.com/";
response = urllib2.urlopen(url, context=ctx);
Here is the Error:
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>
How do I fix this issue?
The API recently deprecated TLS 1.0 support which is causing the issue. I am now working on upgrading python to use TLS1.2 which is also very challenging as Mac default install of Python only supports TLS 1.0.