0

I am getting an error while attempting to read one value from a json. The response from "https://status.mojang.com/check" is a list, which I then attempt to use only one element of. This gives me the Command raised an exception: KeyError: 'data' error.

My code

    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)
Dextication
  • 873
  • 2
  • 12
  • 26
  • 2
    Looks like the object MineCraftNet hasn't a field call "data". Could you print the json sgring received from the get request? – S-Wing Jan 11 '18 at 08:52
  • 1
    If you look at the json data you'll notice that it doesn't have a "data" key, and that "minecraft.net" is at the root level of the data. Try `MinecraftNet["minecraft.net"]`. – Aran-Fey Jan 11 '18 at 08:57

1 Answers1

1

After executing

MinecraftNet = json_data[0]

your MinecraftNet object contains

{
    minecraft.net: "green"
}

so the next call

MinecraftNet = MinecraftNet["data"]

is wrong.

Change it to

MinecraftNet = MinecraftNet["minecraft.net"]
Northern Poet
  • 1,715
  • 10
  • 15