Python: Requests Module Response in JSON
Date: 2016-09-05 |
**Problem: **I’m using the Requests Module for Python 3.5 to handle my HTTP get and post requests. I know I can get my response in JSON, but I’m having trouble accessing the keys on the response. When access a key that I know is in the response, it’s saying:
AttributeError: 'Response' object has no attribute 'keywords'
What am I doing wrong?
**Solution: **It looks like you’re trying to directly access the requests
module’s Response
object without first extracting the actual response JSON. The Response
object has several built-in functions and parameters that you can use (refer to the documentation linked above for more about that).
To get to the actual JSON response from your request, first extract the JSON object out into a new variable using the module’s .json()
method call then simply access that keyword within the created dictionary using .get('key')
.
Here’s gist to get you started:
[[https://gist.github.com/SIRHAMY/20e6fc335191d0e45a7250786f3fe457](https://gist.github.com/SIRHAMY/20e6fc335191d0e45a7250786f3fe457)]Want more like this?
The best / easiest way to support my work is by subscribing for future updates and sharing with your network.