Steam API与价格问题

时间:2015-04-14 01:17:17

标签: python

嘿那些伙计我试图写出一种方法来推销销售单,但是当我运行这个时,我遇到了某种类型错误,指出列表标记必须是不是strs的内容。

代码:

def steamlibrarypull(steamID, key):
#Pulls out a CSV of Steam appids.
    steaminfo = {
        'key': key,
        'steamid': steamID,
        'format':'JSON',
        'include_appinfo':'1'
    }
    r = requests.get('http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/', params=steaminfo)
    d = json.loads(r.content)
    response = d['response']['games']
    games = {}
    for game in response:
        getprice = requests.get('http://store.steampowered.com/api/appdetails/?appids=%d&filters=price_overview&cc=us' % game['appid'])
        if getprice.status_code == 200:
            rjson = json.loads(getprice.text)
            # use the appid to fetch the value and convert to decimal
            # appid is numeric, cast to string to lookup the price
            try:
                price = rjson[str(game['appid'])]['data']['price_overview']['initial'] * .01
            except KeyError:
                pass
            games[game['name']] = {'price': price, 'appid': game['appid']}
    return games

错误追溯:

Traceback (most recent call last):
  File "steam.py", line 54, in <module>
    print steamlibrarypull(76561197960434622, key)
  File "steam.py", line 49, in steamlibrarypull
    price = rjson[str(game['appid'])]['data']['price_overview']['initial'] * .01
TypeError: list indices must be integers, not str

0 个答案:

没有答案