Error in proxy connection in DSWS API

Proxy connection DSWS.pngOne of our clients wants to connect through proxy when using DSWS API. His code currenlty looks like the attached, but getting following error msg:


HTTPSConnectionPool(host='product.datastream.com', port=443): Max retries exceeded with url: /DSWSClient/V1/DSService.svc/rest/GetToken (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

_get_json_Response : Exception Occured:

HTTPSConnectionPool(host='product.datastream.com', port=443): Max retries exceeded with url: /DSWSClient/V1/DSService.svc/rest/GetToken (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

get_data : Exception Occured

(<class 'Exception'>, Exception('Invalid Token Value'), <traceback object at 0x0000029FA02A7788>)

Traceback (most recent call last):

File "C:\ProgramData\Anaconda3\lib\site-packages\DatastreamDSWS\DS_Response.py", line 146, in get_data

raise Exception("Invalid Token Value")


Please assist. Thank you.

Tagged:

Best Answer

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @bob.kim

    On Windows, the Datastream Python library uses the wincertstore package to load the Windows certificate file.

    The code looks like this:

    import requests
    import wincertstore
    cfile = wincertstore.CertFile()
    cfile.addstore('CA')
    cfile.addstore('ROOT')
    cfile.addstore('MY')

    proxy="http://<proxy>:<port>&quot;
    url = 'https://product.datastream.com/DSWSClient/V1/DSService.svc/rest/GetToken';
          
    myobj = {"Password": "<password>", 
             "Properties": [{"Key": "__AppId", "Value": "PythonLib-1.1.0"}], 
             "UserName": "<username>"}


    x = requests.post(url, json = myobj, proxies={'http':proxy, 'https':proxy}, verify=cfile.name)


    print(x.status_code)
    print(x.text)


Answers