So I have a Discord BOT using python and I am trying to get print the JSON information using the Enjin API. I can get it to print everything if I do print(Data)
, but as soon as I try displaying a certain bit of information, such as the variables_values
, it doesn't display and gives me the following error:
Command raised an exception: TypeError: list indices must be integers or slices, not str
I have a previous function; called Status
that uses a different API, and I can get it to work with that, but I just cannot get the following code to display the values in variables_values
bracket. (As you can tell, I am not great with JSON | Also, ignore the xxxxx )
async def GetVariable(message):
R = requests.get('http://www.xxxxxx.co.uk/api/m-shopping-purchases/m/47325895/user_id/19363576')
Data = R.json()
await client.say(Data["varaible_values"])
Here is what I want displayed, when I run the ?GetVariable command: jacobdallred
- which is in the "variables_values":{"Steam64ID":"jacobdallred"}
place.
Instead, it gives me the error previously mentioned.
Here is what it displays if I only client.say(Data)
: (Uploading to Hastebin to display nicer) https://hastebin.com/huwubiwawe.json
You need to access the first element of that json
response array. Like this:
await client.say(Data[0]["items"][0]["variables_values"]["Steam64ID"])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.