question

Upvotes
Accepted
1 0 1 0

KeyError: 'DataResponse' when running ds.get_data(tickers='VOD', fields='P', kind=0)

I'm getting this error message running the simple example from the "Datastream Web Service Getting Started with Python Guide". This was running fine a few days ago. Any suggestions, please?

datastream-apidsws-apikey-error
icon clock
10 |1500

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

1 Answer

Upvotes
Accepted
38.1k 71 35 53

@daniel.fenn

It may receive an invalid response from the server.

To verify the retrieved response, please run this code when the problem occurred.

import requests
post_msg =    {
        "DataRequest": {
            "DataTypes": [
                {
                    "Properties": None,
                    "Value": "P"
                }
            ],
            "Date": {
                "End": "",
                "Frequency": "",
                "Kind": 0,
                "Start": ""
            },
            "Instrument": {
                "Properties": None,
                "Value": "VOD"
            },
            "Tag": None
        },
        "Properties": {
            "Key": "Source",
            "Value": None
        },
        "TokenValue": ds.tokenResp['TokenValue']
    }

res = requests.post("https://product.datastream.com/DSWSClient/V1/DSService.svc/rest/GetData", json=post_msg)
print(res.status_code)
print(res.headers)
print(res.text)

The output looks like:


200
{'Content-Type': 'application/json; charset=utf-8', 'Server': 'Microsoft-IIS/10.0', 'X-Powered-By': 'ASP.NET', 'Date': 'Tue, 16 Jun 2020 05:22:20 GMT', 'Content-Length': '266'}
{"DataResponse":{"AdditionalResponses":null,"DataTypeNames":null,"DataTypeValues":[{"DataType":"P","SymbolValues":[{"Currency":"£ ","Symbol":"VOD","Type":5,"Value":124.46}]}],"Dates":["\/Date(1592179200000+0000)\/"],"SymbolNames":null,"Tag":null},"Properties":null}

From the output, there is a "DataResponse" key in the response.

icon clock
10 |1500

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

Click below to post an Idea Post Idea