Python3 key error on keys that exist?
Clash Royale CLAN TAG#URR8PPP
Python3 key error on keys that exist?
I get a KeyError: 'date/homeTeam/awayTeam'
on a list of objects that are structured like this:
KeyError: 'date/homeTeam/awayTeam'
'_id':
'$oid': '5b68f822cf785e0013cb7702'
,
'date': 'Sun, 05 Aug 2018 23:00:00 GMT',
'homeTeam': 'Stone Cold Killers',
'awayTeam': 'Danglers'
Though if I try to get the id
it works. This is what I am using to get the data:
id
json.loads(dumps(match))['homeTeam']
Traceback: https://pastebin.com/Utykdxkh
Sure I updated with a pastebin of it wasnt sure how to make it formatted on here
– amedeiros
Aug 12 at 1:51
You should rework your code a bit so that you print the dictionary before doing the key lookup. Then the last dictionary it prints will be the one that's failing.
– Patrick Haugh
Aug 12 at 1:54
@amedeiros what is output of
json.loads(dumps(match))
. Can you print it and add it to the question?– the-realtom
Aug 12 at 2:01
json.loads(dumps(match))
I think I found the issue thanks to Patrick. I forgot that one of the records has DATE instead of date which is what is causing the issue I am assuming
– amedeiros
Aug 12 at 2:11
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Could you share the full error traceback? I don't think that line is the one responsible for that error message.
– Patrick Haugh
Aug 12 at 1:48