0

I am trying to read data from ODATA and later on create dataframes using python.

import requests import pyodata import json import pandas as pd

When using pyodata

Method 1

SERVICE_URL = 'https://xxx/sap/opu/odata/sap/Table_0001'

or

SERVICE_URL = 'https://xxx/opu/odata/Table_0001/?$format=json'

HTTP_LIB=requests.Session()
HTTP_LIB.auth = ('username', 'password')
HTTP_LIB.verify=False

I have the following issue:

<<bound method Service.http_get_odata of <pyodata.v2.service.Service object at 0x000001B491BD58D0>>

when using requests only Method 2

import pyodata
import requests
import json


r=requests.get('https://xxx/opu/odata/Table_0001/?$format=json', auth=('Username', 'Password'), verify=False)


print(r.status_code)

print(r.json())

I am connected to ODATA but i cant select the the data from table and i have the following output

{'d': {'EntitySets': ['Table_0001', 'AdditionalMetadata']}}

I tried loading ODATA in excel and it is working.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Bruno05
  • 21
  • 1
  • 2

2 Answers2

2

Problem solved,

There was an issue with the data provided in the URL.

Somehow excel was able to read it!

However i confirm that method 2 it is working perfectly!

Bruno05
  • 21
  • 1
  • 2
0

I've gave an answer here

Here is an example code:

import requests
import pyodata
import pandas as pd

SERVICE_URL = 'http://services.odata.org/V2/Northwind/Northwind.svc/'
HTTP_LIB = requests.Session()
northwind = pyodata.Client(SERVICE_URL, HTTP_LIB)

# query everything of entity set customers
customers = northwind.entity_sets.Customers.get_entities().execute()

schema = service.schema
entity_type = next(et for et in schema.entity_types if et.name == "Customer")
properties = entity_type.properties()

def monta_prop_dict(obj, properties):
    d = {}
    for prop in properties:
        d[prop.name] = getattr(obj, prop.name)
    return d

data = []
for c in customers:
    data.append(monta_prop_dict(c, properties))

df = pd.DataFrame(data)
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
neves
  • 33,186
  • 27
  • 159
  • 192