0

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?

4
  • I think u need to add the positional argument in {}. For example it should be : matchinfo = requests.get("api.opendota.com/api/matches{0}".format(str(x))).json()["match_id"] Commented Nov 29, 2018 at 9:11
  • 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. Commented Nov 29, 2018 at 9:14
  • Your solution did not work, but I added the {0} in my code and it looped through more IDs but ultimately returned a KeyError prior to finishing the list. Commented Nov 29, 2018 at 9:17
  • @ShivamSingh This seems to be the cause that raises the KeyError! Commented Nov 29, 2018 at 9:21

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.