How to Fix: AttributeError: ‘Response’ object has no attribute ‘json’

3D illustration of a robot looking for a label on a box instead of pressing the button, representing the missing parentheses on the json method.

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().

โšก Quick Fix: AttributeError: ‘Response’ object has no attribute ‘json’ โ€” Python requests.get() Missing Parentheses Fix and API JSON Parsing Pattern

You typed response.json without () โ€” Python read it as a reference to the method object itself, not a call to execute it, and the result is not a dictionary.

# WRONG โ€” no parentheses: returns the method object, not the parsed data
import requests
response = requests.get("https://api.example.com/data")
data = response.json          # AttributeError: 'Response' object has no attribute 'json'
print(data['key'])            # crashes โ€” data is a bound method, not a dict

# RIGHT โ€” add () to call the method and parse the JSON into a dictionary
data = response.json()        # executes the method โ€” returns a Python dict
print(data['key'])            # works

# RIGHT โ€” production pattern: check status before parsing
import requests
response = requests.get("https://api.example.com/data")
response.raise_for_status()  # raises HTTPError on 4xx/5xx โ€” stops bad parses early
data = response.json()
print(data['key'])

Always call response.json() with parentheses โ€” every other Response attribute (status_code, text, headers, url) is a plain attribute without (), but json() is a method that actively parses the response body.

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_code is an attribute. It’s just a number (like 200).
  • response.text is an attribute. It’s just a string of text.
  • response.json() is a method. It’s an action that tells Python to read the response.text and 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 ()?”


AttributeError: ‘Response’ object has no attribute ‘json’ โ€” The () Rule and the Four Response Attributes Every API Developer Needs

AttributeError: ‘Response’ object has no attribute ‘json’ almost always means one missing character: the closing parenthesis. response.json references the method. response.json() calls it, parses the body, and returns a Python dictionary.

Know these four Response attributes and which ones need () :

response.status_code โ†’ integer, no () โ€” HTTP status (200, 404, 500)
response.text โ†’ string, no () โ€” raw response body as text
response.headers โ†’ dict, no () โ€” response headers
response.json() โ†’ dict, needs () โ€” parses JSON body into Python dict

The one extra check that prevents silent data corruption: call response.raise_for_status() before response.json(). A 404 or 500 response still has a body โ€” sometimes a valid JSON error message โ€” and response.json() parses it without complaint. raise_for_status() raises an HTTPError immediately on any 4xx or 5xx code, stopping you from treating an error response as valid data.

import requests

try:
response = requests.get("https://api.example.com/data")
response.raise_for_status() # stops here on 4xx/5xx
data = response.json() # only runs on 2xx
print(data['key'])
except requests.exceptions.HTTPError as e:
print(f"API error: {e}")
except requests.exceptions.JSONDecodeError:
print("Response is not valid JSON.")

The JSONDecodeError catch matters for one edge case: an API that returns status 200 but sends HTML or plain text instead of JSON โ€” a server misconfiguration that response.json() crashes on with a JSONDecodeError, not an AttributeError. Both exceptions belong in every production API call.

Similar Posts

Leave a Reply