I have a response object from a request in the form of:
url = 'http://localhost:8000/some-endpoint'
body = {
'key': 'val'
}
response = requests.post(url, json=body)
And would like to access a key from the response in the form of:
[
[
"{\"somekey\": \"abcabcabc\", \"expires_in\": 86400}"
]
]
I have tried using various methods for accessing someKey
but get errors
response.json()
# TypeError: unhashable type: 'dict'
json.dumps(response).json()
# TypeError: Object of type Response is not JSON serializable
response[0]['somekey']
# TypeError: 'Response' object is not subscriptable
response.get('somekey')
# AttributeError: 'Response' object has no attribute 'get'
response.text
["{\"access_token\": \"j9U9QHChSrEVitXeZSv400AQfq3imq\", \"expires_in\": 86400, \"token_type\": \"Bearer\", \"scope\": \"read write\"}"]
response.text.json()
# 'str' object has no attribute 'json'
How can I access the value of somekey
?
Note: response
object is being wrapped for debugging in Postman like:
return Response({
res.json().get('access_token')
}, status=200)