Cannot connect to DSWS via Python

Options

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

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    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.

Answers