使用Steam API时出现Python. KeyError

nfs0ujit  于 2022-12-21  发布在  Python
关注(0)|答案(1)|浏览(162)

当使用python和steam API试图使用data = profile['gameextrainfo']获取某个值时,profile具有API的值,即.

{"response":{"players":[{"steamid":"76561199446676130","communityvisibilitystate":3,"profilestate":1,"personaname":"S7 WatchDog󠀡󠀡󠀡󠀡","profileurl":"https://steamcommunity.com/profiles/76561199446676130/","avatar":"https://avatars.akamai.steamstatic.com/415bd0e2ddd5d8e99309eec6d7a2566cbb09022d.jpg","avatarmedium":"https://avatars.akamai.steamstatic.com/415bd0e2ddd5d8e99309eec6d7a2566cbb09022d_medium.jpg","avatarfull":"https://avatars.akamai.steamstatic.com/415bd0e2ddd5d8e99309eec6d7a2566cbb09022d_full.jpg","avatarhash":"415bd0e2ddd5d8e99309eec6d7a2566cbb09022d","personastate":1,"primaryclanid":"103582791429521408","timecreated":1671522419,"personastateflags":0,"gameextrainfo":"Counter-Strike: Global Offensive","gameid":"730"}]}}

我似乎无法过滤掉任何键。我尝试了所有的键,但python就是找不到它们。有什么想法吗
已尝试所有键。已尝试使用requests python模块

ht4b089n

ht4b089n1#

您可以使用json模块来解析响应并访问各个数据点。

import json 
data = json.loads(profile) 
gameextrainfo = data['response']['players'][0]['gameextrainfo'] 
print(gameextrainfo)

相关问题