First, you are trying to access an element in a string, not a dictionary. r.text
simply returns the plain text of the request. To get the proper dictionary from a requests
object, use r.json()
.
When you try r.json()[stream]
, Python thinks that you are looking for the value in the dictionary corresponding to they key located in variable stream
. You have no such variable. What you want is the value corresponding to the key of the literal string 'stream'. Therefore, r.json()['stream']
should give you what you the next nested dictionary. If you want that url, then r.json()['stream']['_links']['self']
should return it.
See Ashwini's answer for why print r.text
and r.text
are different.