Common causes
- An HTTP request returned an empty body, HTML error page, or plain text instead of JSON
- The JSON string has a syntax error: trailing comma, unquoted keys, or single quotes
- You called json.loads() on an empty string or None
- The response was truncated or partially received
How to fix it
- Print the raw response before parsing to see what you actually received: print(response.text)
- Check the HTTP status code before parsing: if response.status_code == 200:
- Wrap in try/except: try: data = json.loads(text) except json.JSONDecodeError: ...
- Validate the JSON string at jsonlint.com if you're constructing it manually
Example
Traceback (most recent call last):
File "app.py", line 6, in <module>
data = json.loads(response.text)
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)Parsing an API response that returned an empty string because the request failed
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
