Hi All,
I’m fairly new to Python and playing with APIs so I’m sure this may be a fairly easy question or rookie mistake. I’m currently trying to pull player ranking for an individual player from the Matches for Player endpoint. My goal is to bring each ranking into a list, and then determine how many times a player got 1st place in a given number of Warzone games. I’m currently allowing for a user to enter their gamertag, and how many games they would like to iterate through.
The issue is that for some reason, if I enter any number of 25 for the games to iterate through, I receive the “list index out of range” error. The script runs perfectly fine through every number of games through 25, and I’m not sure why that might be. Any ideas? Currently the script below is set to count how many times a player gets 1st place in however many games you input. I’d like to see these figures for more than 25 games but can’t figure out why i’m getting an error upon inputting anything >25.
> import requests, pprint
> pp = pprint.PrettyPrinter(indent=4)
>
> query = raw_input(“What is your GamerTag?”)
> games = raw_input(“How many games do you want to scan?”)
>
> uri = ‘https://www.haloapi.com/stats/h5/players/’+str(query)+’/matches’
> headers = {‘Ocp-Apim-Subscription-Key’: ‘000000000000000000000000000’}
> params = {‘players’: str(query),
> ‘matches’: ‘warzone’,
> ‘start’: ‘0’,
> ‘count’: str(games)}
> response = requests.get(uri, params=params, headers=headers)
> data = response.json()
>
> r_list =
> x=0
> int_games=int(games)
> while x<int_games:
> rank=data[‘Results’][‘Players’][0][‘Rank’]
> x+=1
> r_list.append(rank)
>
> print r_list
> print r_list.count(1)
You can only ever pull a maximum of 25 games down at a time. Have a read of the ‘start’ and ‘count’ parameters of the query you’re building.
To get more than 25 games, you’ll need to make multiple requests.
Example: Request the latest 100 games for a player.
Request #1: Matches 1-25 (Start = 0, Count = 25)
Request #2: Matches 26-50 (Start = 25, Count = 25)
Request #3: Matches 51-75 (Start = 50, Count = 25)
Request #4: Matches 76-100 (Start = 75, Count = 25)
> 2753093343646559;2:
> You can only ever pull a maximum of 25 games down at a time. Have a read of the ‘start’ and ‘count’ parameters of the query you’re building.
>
> To get more than 25 games, you’ll need to make multiple requests.
>
> Example: Request the latest 100 games for a player.
>
> Request #1: Matches 1-25 (Start = 0, Count = 25)
> Request #2: Matches 26-50 (Start = 25, Count = 25)
> Request #3: Matches 51-75 (Start = 50, Count = 25)
> Request #4: Matches 76-100 (Start = 75, Count = 25)
Thanks for the reply. I’ve been working on my script on and off for a while now and have hit another snag I can’t seem to overcome. I read the documentation and it doesn’t seem to mention anything about this, I was curious if you had any insight. What I’m trying to do is iterate through warzone matches and pull the value from Results->Player->Rank to get the team-agnostic rank for a player in their games of Warzone. Thanks to your advice above, I’ve successfully been able to iterate through sets of 25 games of Warzone pulling this value and adding them to a list.
The issue I’m seeing is that for some reason, if I try to scan over 250 games, I receive the following error:
Traceback (most recent call last):
File “C:/Python27/Halo_WZ_Team_Rank_Multi_Sets_all_placements_2_data.py”, line 42, in <module>
rank=data[‘Results’][‘Players’][0][‘Rank’]KeyError: ‘Results’
It seems that it’s having trouble finding the “Results” portion of the data after 250 games. I’m having no problem pulling the data with a start value of 250, but for some reason iterating through different games seems to have an issue once I hit #250, regardless of the start point.
Essentially, the script pulls this value starting with start=0 and count=25. The loop adds 25 to the start each time depending on how many games I want to iterate through. but it seems that going beyond 250 games causes the above error. Is there something I may have missed in the documentation that might explain this?
Thanks
It’s also worth adding that for some point, when i actually print the raw data along with my query, it doesn’t have a problem going over 250. But obviously printing the data from this endpoint for over 250 games isn’t ideal. It’s only when I do not print the raw data that I see the above error. I’m not sure how to explain that one. I’m curious if there’s an error in my script that would cause this somehow.