Search code examples
pythonpython-requestssteam-web-api

Steam Web API IPlayerService response empty after certain amount of requests


I'm writing a Python script that keeps track of my playtime. Every 30 seconds I 'refresh' the data I get from the Steam Web API. But after a certain amount of calls (around 60), the response is totally empty.

I am aware of the maximum of 100.000 API calls per day, but it doesn't seem like I'm getting rate-limited, because I also tested refreshing every 60 seconds, even every 5 minutes, but it always is empty after around 60 calls.

Here's some of the code:


from steam.webapi import WebAPI
from time import sleep

api = WebAPI(API_KEY, raw=False, format='json', https=True, http_timeout=10)

def game_data(steamids):

    data = api.call('IPlayerService.GetOwnedGames', appids_filter=None, include_appinfo=True, include_free_sub=True, include_played_free_games=True, steamid=steamids)

    return data['response']['games']

while True:
    g_data = game_data(steamids)   
    playtime = []

    for i in g_data:
        playtime.append(i['playtime_forever'])

    print(playtime)
            
    sleep(30)

Output

{"response":{}}

I'm using the steam library, which works basically the same as requesting data with the request library. It seems like the problem is only with the IPlayerService interface.

Output of the error

In the image above I counted the amount of requests, and as you can see, the 60th request failed. It raises a keyError exception, because the response is empty.

Please let me know if you need any other information, and hopefully someone knows how to fix this.

Thanks in advance!


Solution

  • So I just found a fix, instead of GetOwnedGames use GetRecentlyPlayedGames.

    This one doesn't seem to have a limit of 60, which the other one has. It's basically the exact same response, except it only returns games that have been played in the past 2 weeks, which is totally fine for my use.