简体   繁体   中英

Python: KeyError but both key and value exists

I'm fetching information from the opendota API. I've previously taken out a .csv list with approx. 160 match_ids which I want some more information from and then append certain values to a list.

With the code below, While looping through the list I receive a KeyError.

for x in finallist:
    matchinfo = requests.get("https://api.opendota.com/api/matches/{}".format(x)).json()["match_id"]
    print(matchinfo)

The KeyError is raised on a certain ID's, but if I use the code below, I get no KeyError and I see the information.

matchspec = requests.get("https://api.opendota.com/api/matches/4184421518").json()['match_id']
matchspec

So through this, 4184421518 prints information, but in the loop it stops at that ID and a couple more IDs below that. Why do I receive a KeyError in the for loop, but not when I specifically ask for the information?

Opendota api is rate limited to 60 requests/min. Make sure you are not exceeding that, as it seems like an error with the api response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM