-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems extracting odata #29
Comments
Your issue lies in the following two lines, default = 'Geids'
Order = Service.entities.get('Geids', default) This is due to the fact the odata library wasn't able to read your XML response correctly (this was a recurring issue for me, I eventually ended up changing the XML namespaces under if 'Geids' not in Service.entities:
print('No geids entity definition found.')
exit()
Order = Service.entities['Geids'] |
Hi, Where exactly did you change the XML namespace? In the "metadata.py" ? But I noticed that when trying the following lines: Best regards, |
Some new comment from my side. I looked deeper in the original data and noticed that the odata service provides JSON files. The question now is: Does that have an influence and if yes, where do I have to change it? Best regards, |
It looks like you're trying to use entities that aren't defined. The library requires reflect_entities or it will not populate the entities list. Try something like this: Service = ODataService(url, auth=my_auth, reflect_entities=True) A second problem that I had is with the location of the metadata (XML). In your example, the library would look for it here: http://source.com/cdsodata/$metadata/ If that doesn't return the metadata XML, the library won't be able to build the entities. In my case, I had to use pull request #26 by nicenemo. It includes a fix to the metadata url to not have the trailing slash. To answer your question: the library expects that the OData service uses JSON except for the metadata XML file. Tim |
Hi @tpow , I've added the reflect_entities but still no effect. So that can't be the issue here. Ok, but all entities are in json format, so that can't be neither the problem. Here are two examples of the entities (the first from https://source/cdsodata and the second from the Geids): |
Your examples all have $metadata without a trailing slash. Does your OData site return the metadata if you add a slash after $metadata like /cdsodata/$metadata/? If not, you'll need pull request #26 by nicenemo. Tim |
Hi, yes it is also returning values when I add the slash ( https://source/cdsodata/$metadata/). So I think #26 will not help here? |
Hi @4quen, Perhaps enabling logging would give you some insight? Here's code similar to what I'm using to test things:
If you're using basic auth, the above should work for you. Also, in a web browser does both Also, does the following give JSON results? Tim |
Hi, I activated the log and received the following lines:
And yes all of your three examples showed the expected results. |
The 403 error indicates that the problem isn't with python-odata, but with your credentials, the access method, or the url. Perhaps you can't connect to that site using basic auth? If you need to authenticate before loading the $metadata url with a browser then you'll need to mimic that before python-odata will work. You might try connecting using the Requests module first and once you get that working I suspect python-odata will work fine. In my previous example, I'd try replacing the Service = odata.ODataService line and everything following it with something like this:
You can then make changes to your authentication process until the response prints <Response [200]> and you see the xml from the metadata. For example, you should double check the credentials and url. If you're filling out a form in your browser before you can access the odata provider, you might need to post to the form URL (s.post) and then call the ODataService. Good luck! |
I really don't know if this is the right place to write my problem here. If not, pardon me!
I tried out the library but I ran into the following error:
I'm quite sure I did everything right (and I also doublechecked the providing oDataService if the values were set right). Also username and password are right.
This is my code:
`from odata import ODataService
from requests.auth import HTTPBasicAuth
import requests
url = 'http://source.com/cdsodata/'
my_auth = HTTPBasicAuth('XXX', 'YYY')
Service = ODataService(url, auth=my_auth)
default = 'Geids'
Order = Service.entities.get('Geids', default)
query = Service.query(Order)
query = query.limit(100)
for entity in query:
print(entity.Geid)`
Maybe you can help me?
The text was updated successfully, but these errors were encountered: