Hi,
I am trying to use Python to access DSS REST API and I got the result all time correctly. But in recent days, I got the error about SSLError. I am not sure what happened. Could you please help to see whether my account issue or DSS REST API issue?
Here is the code:
import requests, json
from requests import Request, Session
from collections import OrderedDict
urlGetToken = 'https://hosted.datascopeapi.reuters.com/RestApi/v1/Authentication/RequestToken'
header1 = {'Content-Type': 'application/json'}
tokenRequestBody = json.dumps({'Credentials': {'Password': '<password>', 'Username': '<username>'}})
response = requests.post(urlGetToken, tokenRequestBody, headers = header1)
statusCode = response.status_code
if statusCode != 200:
print('ERROR: Get Token failed with HTTP status code: ' + str(statusCode))
sys.exit(-1)
else:
result = response.json()
token = result['value']
print(token)
Here is the error message thrown from Python
---------------------------------------------------------------------------
SysCallError Traceback (most recent call last)
/anaconda3/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
440 try:
--> 441cnx.do_handshake()
442 except OpenSSL.SSL.WantReadError:
/anaconda3/lib/python3.6/site-packages/OpenSSL/SSL.py in do_handshake(self)
1805 result = _lib.SSL_do_handshake(self._ssl)
-> 1806self._raise_ssl_error(self._ssl, result)
1807
/anaconda3/lib/python3.6/site-packages/OpenSSL/SSL.py in _raise_ssl_error(self, ssl, result)
1537 if errno != 0:
-> 1538raise SysCallError(errno, errorcode.get(errno))
1539 raise SysCallError(-1, "Unexpected EOF")
SysCallError: (54, 'ECONNRESET')
During handling of the above exception, another exception occurred:
SSLError Traceback (most recent call last)
/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
600 body=body, headers=headers,
--> 601 chunked=chunked)
602
/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
345 try:
--> 346self._validate_conn(conn)
347 except (SocketTimeout, BaseSSLError) as e:
/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in _validate_conn(self, conn)
849 if not getattr(conn, 'sock', None): # AppEngine might not have `.sock`
--> 850conn.connect()
851
/anaconda3/lib/python3.6/site-packages/urllib3/connection.py in connect(self)
325 server_hostname=hostname,
--> 326 ssl_context=context)
327
/anaconda3/lib/python3.6/site-packages/urllib3/util/ssl_.py in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir)
328 if HAS_SNI: # Platform-specific: OpenSSL with enabled SNI
--> 329return context.wrap_socket(sock, server_hostname=server_hostname)
330
/anaconda3/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
447 except OpenSSL.SSL.Error as e:
--> 448raise ssl.SSLError('bad handshake: %r' % e)
449 break
SSLError: ("bad handshake: SysCallError(54, 'ECONNRESET')",)
During handling of the above exception, another exception occurred:
MaxRetryError Traceback (most recent call last)
/anaconda3/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
439 retries=self.max_retries,
--> 440timeout=timeout
441 )
/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
638 retries = retries.increment(method, url, error=e, _pool=self,
--> 639 _stacktrace=sys.exc_info()[2])
640 retries.sleep()
/anaconda3/lib/python3.6/site-packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
387 if new_retry.is_exhausted():
--> 388raise MaxRetryError(_pool, url, error or ResponseError(cause))
389
MaxRetryError: HTTPSConnectionPool(host='hosted.datascopeapi.reuters.com', port=443): Max retries exceeded with url: /RestApi/v1/Authentication/RequestToken (Caused by SSLError(SSLError("bad handshake: SysCallError(54, 'ECONNRESET')",),))
During handling of the above exception, another exception occurred:
SSLError Traceback (most recent call last)
<ipython-input-4-ae8e97f611da> in <module>()
6 header1 = {'Content-Type': 'application/json'}
7 tokenRequestBody = json.dumps({'Credentials': {'Password': 'xxx', 'Username': 'xxx'}})
----> 8response = requests.post(urlGetToken, tokenRequestBody, headers = header1)
9 statusCode = response.status_code
10 if statusCode != 200:
/anaconda3/lib/python3.6/site-packages/requests/api.py in post(url, data, json, **kwargs)
110 """
111
--> 112return request('post', url, data=data, json=json, **kwargs)
113
114
/anaconda3/lib/python3.6/site-packages/requests/api.py in request(method, url, **kwargs)
56 # cases, and look like a memory leak in others.
57 with sessions.Session() as session:
---> 58return session.request(method=method, url=url, **kwargs)
59
60
/anaconda3/lib/python3.6/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
506 }
507 send_kwargs.update(settings)
--> 508resp = self.send(prep, **send_kwargs)
509
510 return resp
/anaconda3/lib/python3.6/site-packages/requests/sessions.py in send(self, request, **kwargs)
616
617 # Send the request
--> 618r = adapter.send(request, **kwargs)
619
620 # Total elapsed time of the request (approximately)
/anaconda3/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
504 if isinstance(e.reason, _SSLError):
505 # This branch is for urllib3 v1.22 and later.
--> 506raise SSLError(e, request=request)
507
508 raise ConnectionError(e, request=request)
SSLError: HTTPSConnectionPool(host='hosted.datascopeapi.reuters.com', port=443): Max retries exceeded with url: /RestApi/v1/Authentication/RequestToken (Caused by SSLError(SSLError("bad handshake: SysCallError(54, 'ECONNRESET')",),))