2
votes

I am stuck on this problem I would like to request this URL, which is in a ODATA format

http://services.odata.org/V3/OData/OData.svc/Products?$format=json

and that comes from this link

https://blogs.msdn.microsoft.com/leohu/2013/10/04/odata-and-json-payload-examples/

I tried with the following code but it doesnt work

from odata import ODataService

url_test = "http://services.odata.org/V3/OData/OData.svc/Products?
$format=json"

service = ODataService(url, reflect_entities=False)

service.entities['ID']

My end goal is to retrieve all the different ID with their Price.

Thanks

I have this error message


KeyError Traceback (most recent call last) in () 3 service 4 ----> 5 service.entities['ID']

KeyError: 'ID'

1
Is there any error message?Sam Xu

1 Answers

1
votes

I do not really know the module OData. It seems to be deprecated, abandoned or similar as you could see on the Pypi repository (link). Anyways, have you tried retrieving the data using requests?

import requests

url_test = 'http://services.odata.org/V3/OData/OData.svc/Products?$format=json'

r = requests.get(url_test)

r_json = r.json()
for value in r_json['value']:
    print(value['ID'])

This seems to work for me.