Cannot connect to DSWS via Python

Using the below code:
import DatastreamDSWS as DSWS
ds = DSWS.Datastream(username = 'XXXX', password = "XXXX")
I get the following error: Token Request : Unexpected error
I am still able to connect to Datastream using the PyDSWS package:
ds = PyDSWS.Datastream(username='XXXX', password='XXXX')
So I don't believe it's a permissioning issue.
Our firm recently had product.datastream.com whitelisted so that we can access the service, but I believe this requires a proxy setting for requests package in python. In the old (PyDSWS) package this required adding a proxy setting to the requests.get call
ie
proxy = {'http': 'http://proxy.xxx.com'}
requests.get(url, proxies = proxy)
Any idea how to add this setting in the new DatastreamDSWS package?
Best Answer
-
It works fine on my machine with Python 3.7 64-bit and Requests 2.21. Please verify the versions of Python and Requests libraries.
You may need to run the following code to verify the problem.
import DatastreamDSWS as DSWS
import requests
import json
import os
url = "https://product.datastream.com/DSWSClient/V1/DSService.svc/rest/"
token_url = url + "GetToken"
def json_Request( raw_text):
jsonText = json.dumps(raw_text)
byteTemp = bytes(jsonText,'utf-8')
byteTemp = jsonText.encode('utf-8')
jsonRequest = json.loads(byteTemp)
return jsonRequest
os.environ['HTTP_PROXY']="http://127.0.0.1:8080"
os.environ['HTTPS_PROXY']="http://127.0.0.1:8080"
tokenReq = {"Password":'<password>',"Properties":[{'Key':'__AppId','Value':"PythonLib 1.0"}],"UserName":'<username>'}
json_tokenReq = json_Request(tokenReq)
json_ResponseRaw = requests.post(token_url, json=json_tokenReq)
print(json_ResponseRaw.status_code, json_ResponseRaw.text)
json_Response = json_ResponseRaw.json()
print(json_Response["TokenValue"])We need to verify which line throws the exception.
0
Answers
-
You can set a proxy via environment variables.
set https_proxy=http://127.0.0.1:36036
set http_proxy=http://127.0.0.1:36036Moreover, you can set the environment variables via the Python code.
import os
os.environ['HTTP_PROXY']="http://127.0.0.1:8889"
os.environ['HTTPS_PROXY']="http://127.0.0.1:8889"0 -
Thanks, seems like that worked for setting the proxy, although now I'm encountering a different error:
import DatastreamDSWS as DSWS
import os
os.environ['HTTP_PROXY'] = "http://xxxx.xxxx:xx"
os.environ['HTTPS_PROXY'] = "http://xxxx.xxxx:xx"
ds = DSWS.Datastream(username = 'XXXX', password = "XXXX")
Running the above I get the error: JSON decoder error while posting Token request
Any ideas on this issue? I am able to pull data from my laptop, so I don't believe its an issue with my credentials
0 -
The above seems to work, I don't get an exception
Using the above code:
print(json_ResponseRaw.status_code, json_ResponseRaw.text)
Result: 200 {"Properties":null,"TokenExpiry":"\/Date(1562961104528)\/","TokenValue":"Gz2mKM6I5GIVXFF7FepWV6kUYD4GrPnu6Z42LWoXJZxZj8t27YV82gyIwYmvidr8s3y7LXlyJrvv+KG6dDkddYWbm6p8cd3SsAoDWMDjrBVcM8p9nZzxXKqCAGvMDTLb2RwJLR4Nn8dDNO\/Yfz2EkaUkmuO63cphTAI5GwPoJwwEcDSXunOQ7Ymngg+Ras6\/9hABsGVvN811fzlVj5xeK\/Y1YdO8\/uSC7IqLDWui89U=CA0A0609A1DDAB5190574B505AC680FC70CD1680"}
print(json_Response["TokenValue"])
Result: Gz2mKM6I5GIVXFF7FepWV6kUYD4GrPnu6Z42LWoXJZxZj8t27YV82gyIwYmvidr8s3y7LXlyJrvv+KG6dDkddYWbm6p8cd3SsAoDWMDjrBVcM8p9nZzxXKqCAGvMDTLb2RwJLR4Nn8dDNO/Yfz2EkaUkmuO63cphTAI5GwPoJwwEcDSXunOQ7Ymngg+Ras6/9hABsGVvN811fzlVj5xeK/Y1YdO8/uSC7IqLDWui89U=CA0A0609A1DDAB5190574B505AC680FC70CD1680
ds = DSWS.Datastream(username = 'XXXX', password = "XXXX")
Result: JSON decoder error while posting Token request
Any further ideas?
0 -
Nvm, was just missing a backslash after the URL, its working now, thanks!!
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 37 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 698 Datastream
- 1.5K DSS
- 633 Eikon COM
- 5.2K Eikon Data APIs
- 14 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 6 Trading API
- 2.9K Elektron
- 1.5K EMA
- 257 ETA
- 565 WebSocket API
- 40 FX Venues
- 16 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 25 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 283 Open PermID
- 47 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 24 RDMS
- 2.1K Refinitiv Data Platform
- 800 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
- 122 Open DACS
- 1.1K RFA
- 107 UPA
- 194 TREP Infrastructure
- 232 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 101 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛