question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting "KeyError: 'd'" when reading XML OData

See original GitHub issue

I’m trying to read from this site: http://knesset.gov.il/Odata/ParliamentInfo.svc/

The site is in XML and every table is saved in XML too. For example: http://knesset.gov.il/Odata/ParliamentInfo.svc/KNS_Agenda

When reading with python-pyodata, there is a key error when trying to get entities.

Code:

import requests
import pyodata

SERVICE_URL = 'http://knesset.gov.il/Odata/ParliamentInfo.svc/'

# Create instance of OData client
client = pyodata.Client(SERVICE_URL, requests.Session())

# This is the problematic line
a = client.entity_sets.KNS_Agenda.get_entities().execute()

The exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pyodata/v2/service.py", line 305, in execute
    return self._handler(response)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/pyodata/v2/service.py", line 1102, in get_entities_handler
    entities = content['d']['results']
KeyError: 'd'

Is there a way to fix this?

Thanks in advance,

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
filak-sapcommented, Mar 2, 2020

@aviasd Thank you for taking the time to report this issue. Unfortunately, I do believe the service is OData V3 service which is not supported yet.

I have created an experimental fix which is available on the branch: https://github.com/SAP/python-pyodata/tree/experimental_v3

I was able to run your example without issues with pyodata from that branch. However, I didn’t try to fetch any additional entity sets, so there might be more incompatibilities.

If you have time and you want to help us make pyodata better, please, try to use pyodata from the experimental_v3 branch and report results here.

1reaction
TELangelaarcommented, Apr 17, 2021

Hi, Ran in the same problem as aviasd, experimental branch works for me. Thank you guys for the work on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

KeyError while parsing data from .xml file - python
I found that this KeyError is occurred because some of the files do not contain attribute 'occupied'. To avoid this problem and continue...
Read more >
What is KeyError in Python? Dictionary and Handling Them
Here I am trying to access a key called “D” which is not present in the dictionary. Hence, the error is thrown as...
Read more >
4.1. Data Consumers — Pyslet 0.6.20160201 documentation - Read ...
Let's start with a simple illustration of how to consume data using the DAL API by walking through the use of the OData...
Read more >
How to Fix KeyError Exceptions in Python - Rollbar
The Python KeyError is an exception that occurs when an attempt is made to access an item in a dictionary that does not...
Read more >
Invantive(R) SQL 22.0.101 | Release Notes
Fix XML reading not finding any fields - Improve discovery of database definition changes. ... Do not pass PSQL-only data type variables into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found