I cannot connect and access DSS REST API through Python code
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')",),))
Best Answer
-
Your code is functional, and works fine for me with the same Python version (3.6) on Windows.
This looks like a proxy or firewall issue, especially if you changed nothing to that part of your code, which worked initially but fails since a few days ago. You might want to discuss with your IT team if they changed anything recently.
Can you try running your code from a different machine on a different network, maybe even from home ? That would prove this assumption.
0
Answers
-
Thank you so much, Phuriphanvichai. But do you know what is the issue?
0 -
I can run the code properly. It can connect to the server and get the token.
I don't know how to enable SSL tracing in python. It may relate to your network settings or proxy.
Can you test it with Java Code Examples? You can download the java examples from here.
0 -
I tried Java code sample and it failed again. I think you might be right about guessing the root cause should be network settings or proxy. But i could not find the root cause. I am using Mac Book Pro.
0 -
What is an error from Java? You can use the following JVM argument to enable tracing.
-Djavax.net.debug=all:handshake:verbose
0 -
@jian.kang, did you find the root cause of this issue, did you manage to solve it ?
0 -
Yes, Christiaan. Your assumption is correct. I have consulted with DSS REST API QA team here and some of their team members have similar issues with mine. The issue is coming from DNS resolving and proxy servers. I can run my code now and thank you very much for your idea.
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 690 Datastream
- 1.4K DSS
- 629 Eikon COM
- 5.2K Eikon Data APIs
- 11 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 255 ETA
- 559 WebSocket API
- 39 FX Venues
- 15 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 24 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 279 Open PermID
- 45 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 2K Refinitiv Data Platform
- 713 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 106 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 95 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛