SAP / python-pyodata

Enterprise-ready Python OData client
Apache License 2.0
220 stars 93 forks source link

using pyodata to get json output structure format same as browser results #269

Closed ashdsi closed 8 months ago

ashdsi commented 8 months ago

From the browser, when I access the URL https://services.odata.org/V2/Northwind/Northwind.svc/Customers?$format=json, I get the JSON response with results and _next objects. I'm expecting to get a similar output in python v3.9 but the output format is different.

How should I pass the parameter for format=json and where, so I can get the same output structure as what the browser returns with _results field

Here's the example python script and it's response

import pyodata
import requests

SERVICE_URL = 'https://services.odata.org/V2/Northwind/Northwind.svc/Customers'

northwind = pyodata.Client(SERVICE_URL, requests.Session())

theservicedata = getattr(northwind.entity_sets, 'Customers')

data = theservicedata.get_entities().count(inline=True).execute()

for each in data:
    print(vars(each))

Sample Output

{
   "_logger":"<Logger pyodata.service (WARNING)>",
   "_service":<pyodata.v2.service.Service object at 0x7ff5fed4e8e0>,
   "_entity_set":"EntitySet(Customers)",
   "_entity_type":"EntityType(Customer)",
   "_key_props":[
      "StructTypeProperty(CustomerID)"
   ],
   "_cache":{
      "CustomerID":"ERNSH",
      "CompanyName":"Ernst Handel",
      "ContactName":"Roland Mendel",
      "ContactTitle":"Sales Manager",
      "Address":"Kirchgasse 6",
      "City":"Graz",
      "Region":"",
      "PostalCode":"8010",
      "Country":"Austria",
      "Phone":"7675-3425",
      "Fax":"7675-3426",
      "Orders":[

      ],
      "CustomerDemographics":[

      ]
   },
   "_entity_key":"(""ERNSH"")",
   "_etag":"None"
}
phanak-sap commented 8 months ago

Hi @ashdsi

for quite easy question it is not an easy answer. It the end, it would depend on the question why exactly you want to have the JSON response from odata api at hand. I will point out some generic recommendation since there is no one good answer here.

phanak-sap commented 8 months ago

Hi @ashdsi I am closing this since no response for a week and this is essentially a generic question issue. Feel free to reopen if necessary.