try:
response = requests.get('https://api.twitch.tv/kraken/streams/followed', headers=headers)
data = response.json()
except (KeyError, ValueError):
print("Error - make sure your OAuth is formatted correctly in oauth.txt")
sys.exit(1)
channelName = data["streams"]["channel"]["name"]
channelGame = data["streams"]["channel"]["game"]
channelViewers = str(data["streams"]["viewers"])
streamType = data["streams"]["stream_type"]
print(channelName, channelGame, channelViewers, streamType)
我得到的错误是列表索引必须是整数或片,而不是str
从twitch我得到了一个json字典:
{'streams': [{'_id': 2011610081, 'game': 'Sports & Fitness', 'broadcast_platform': 'live', 'community_id': '', 'community_ids': [], 'viewers': 12399, 'video_height': 900, 'average_fps':59, 'delay': 0, 'created_at': '2020-06-20T12:06:14Z', 'is_playlist': False, 'stream_type': 'live' }
the dictionary is a lot longer
如何访问它而不出错
这是一张你已经看过的清单
使用for循环对其进行Itrate
或选择索引
相关问题 更多 >
编程相关推荐