Skip to content
Advertisement

Struggling to print specific content from a script in python

from the following code:

JavaScript

I am receiving the following response:

JavaScript

But I am struggling the with error message. I’m simply trying to return the btc_balance from the script, but it’s not letting me. And what are byte indicies?

Advertisement

Answer

r.content returns a byte object. So you can decode the bytes to string object first and then use the json module to deserialize to a Python object and access the specific key btc_balance

JavaScript

If r here is requests Reponse object, then it has a .json method which will automatically deserialize the response for you. So you could just do,

JavaScript
Advertisement