Python requests: get attributes from returned JSON string
What's being returned is a JSON string; you need to parse it before you can conveniently use it. Requests can do this for you if you call r.json()
instead of r.text
.
resp = r.json()print resp['origin']print resp['headers']['Host']