
This AttributeError Response object issue is one of the most common typos when working with APIs and the requests library.
It means: “You typed response.json but you meant response.json()“.
The Cause
In Python, there’s a huge difference between an attribute (a piece of data, like a variable) and a method (an action, like a function).
response.status_codeis an attribute. It’s just a number (like200).response.textis an attribute. It’s just a string of text.response.json()is a method. It’s an action that tells Python to read theresponse.textand parse it into a Python dictionary.
Problem Code:
import requests
response = requests.get("https://api.coindesk.com/v1/bpi/currentprice.json")
# This is a method, not an attribute!
data = response.json
# CRASH! AttributeError: 'Response' object has no attribute 'json'The Fix: Add Parentheses
You need to call the method by adding () at the end.
import requests
response = requests.get("https://api.coindesk.com/v1/bpi/currentprice.json")
# THE FIX:
data = response.json() # Call the method
# Now it's a dictionary!
print(data['bpi']['USD']['rate'])If you ever see an AttributeError, your first check should be: “Did I forget the ()?”





