'Using Python library pyodata to access data in Odata

So, I am trying to use the pyodata library in Python to access and download data from Odata.

I tried accessing the Northwind data and it worked. So, i guess the codes i used is ok.

import requests
import pyodata

url_t = 'http://services.odata.org/V2/Northwind/Northwind.svc'

# connection set up
northwind = pyodata.Client(url_t, requests.Session())

# This prints out a single value from the table Customers
for customer in northwind.entity_sets.Customers.get_entities().execute():
    print(customer.CustomerID,",", customer.CompanyName)
    break

# This will print out - ALFKI , Alfreds Futterkiste

I also tried connecting to Odata in excel to see if the codes above return the correct data, and it did.

Click to see the screenshot in excel for Odata connection

Now, using the same code to connect to the data source where I want to pull the data did not work:

#using this link to connect to Odata worked.
url_1 = 'https://batch.decisionkey.npd.com/odata/dkusers'

session = requests.Session()
session.auth = (user_name, psw)
theservice = pyodata.Client(url_1, session)

The above codes return this error message(is it something about security?):

Click to see error message

Connecting to the data in excel looks like this:

Click the view image

I am thinking about it might be security issue that is blocking me from accessing the data, or it could be something else. Please let me know if anything need to be clarify. Thanks.

First time asking question, so please let me know if anything I did not do right here. ^_^



Solution 1:[1]

You got HTTP 404 - Not Found.

The service "https://batch.decisionkey.npd.com/odata/dkusers" is not accessible from outside world for me to try it, so there is something more from networking point of view that happens in the second picture in the Excel import.

You can forget the pyodata at the moment, for your problem it is just wrapper around HTTP networking layer, the Requests library. You need to find a way initialize the Requests session in a way, that will return HTTP 200 OK instead.

Northwind example service is just plain and simple, so no problem during initialization of pyodata.Client

Refer to Requests library documentation- https://docs.python-requests.org/en/latest/user/advanced/

//sample script 
url_1 = 'https://batch.decisionkey.npd.com/odata/dkusers'
session = requests.Session()
session.auth = (user_name, psw)
//??? SSL certificate needs to be provided perhaps? 
//?? or maybe you are behind some proxy that Excel uses but python not.. try ping in CMD
response = session.get(url_1)
print(response.text)

Usable can be pyodata documentation about initialization, however you will not find there the reason why you get HTTP 404 - https://pyodata.readthedocs.io/en/latest/usage/initialization.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1