Reputation: 11
So, I have this tipbot that is working on the deposit function.
I have this code, which I am working on:
d2['data']['balances']['address']
embed=discord.Embed(description="{}".format(d2['data']['balances']['address']), color=0x00ff00)
await client.say(embed=embed)
Yet, after working on this, when I attempt to call the function from the bot, I get the following error:
TypeError: list indices must be integers or slices, not str
What do I need to do to to fix the above code? (I was working on the first line of code.)
The json fragment that I was extracting is:
{'status': 'success', 'data': {'network': 'DOGE', 'available_balance': '0.0', 'pending_received_balance': '0.0', 'balances': [{'user_id': 1, 'label': 'shibe1', 'address': 'A9Bda9UMBcb1183PtsBxnbj5QgP6jwkCFG', 'available_balance': '0.00000000', 'pending_received_balance': '0.00000000'}]}}
Upvotes: 1
Views: 483
Reputation: 544
You need to account for the fact that your JSON returns a list of addresses which, in this case, would mean what you're looking for is actually at d2['data']['balances'][0]['address']
rather than d2['data']['balances']['address']
.
Upvotes: 1