# requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0) while parsing response from 'https://api.example.com/v1/data'

- **ID:** `python/requests-jsondecodeerror-invalid-response`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The server returned a non-JSON response (e.g., HTML error page) but the client expects JSON.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **Check the response status code and content type before parsing JSON** (95% success)
   ```
   response = requests.get('https://api.example.com/v1/data')
if response.status_code == 200 and 'application/json' in response.headers.get('Content-Type', ''):
    data = response.json()
else:
    print('Unexpected response:', response.text)
   ```
2. **Use response.raise_for_status() to catch HTTP errors before parsing** (90% success)
   ```
   response = requests.get('https://api.example.com/v1/data')
response.raise_for_status()
data = response.json()
   ```

## Dead Ends

- **Using json.loads() directly on response.text without checking status** — The response may be an error page, not JSON, causing the same decode error. (80% fail)
- **Setting a custom decoder with strict=False** — The response is not JSON at all, so no decoder can parse it. (90% fail)
