question

Upvotes
Accepted
66 2 5 11

Cannot conned to DSWS via python

Ran the code below to try and ID the issue per the recommendations posted:

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"])

and got back:

ProxyError: HTTPSConnectionPool(host='product.datastream.com', port=443): Max retries exceeded with url: /DSWSClient/V1/DSService.svc/rest/GetToken (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001C898EDBAC8>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it')))
pythondatastream-apidsws-apiproxy
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Upvotes
Accepted
80k 257 52 75

@jgarden

The code uses the local proxy (http://127.0.0.1:8080). You need to make sure that you have a proxy installed on the machine. Otherwise, you can set it to another proxy or remove it.

#os.environ['HTTP_PROXY']="http://127.0.0.1:8080" 
#os.environ['HTTPS_PROXY']="http://127.0.0.1:8080" 

From my test, it can get the response properly when removing the above code.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.