尝试从json读取一个值时出错。来自" https://status.mojang.com/check"的响应是一个列表,然后我尝试只使用其中的一个元素。这给了我Command raised an exception: KeyError: 'data'
错误。
url = "https://status.mojang.com/check"
response = requests.get(url)
json_data = json.loads(response.text)
MinecraftNet = json_data[0]
Accounts = json_data[3]
Auth = json_data[4]
Skins = json_data[5]
Sessions = json_data[7]
API = json_data[8]
MinecraftNet = MinecraftNet["data"]["minecraft.net"]
Accounts = Accounts["data"]["account.mojang.com"]
Auth = Auth["data"]["auth.mojang.com"]
Skins = Skins["data"]["skins.minecraft.net"]
Sessions = Sessions["data"]["sessionserver.mojang.com"]
API = API["data"]["{'api.mojang.com':'"]
print(MinecraftNet, Accounts, Auth, Skins, Sessions, API)
答案 0 :(得分:1)
执行
后MinecraftNet = json_data[0]
您的MinecraftNet
对象包含
{
minecraft.net: "green"
}
所以接下来的电话
MinecraftNet = MinecraftNet["data"]
错了。
将其更改为
MinecraftNet = MinecraftNet["minecraft.net"]