# httpx.HTTPStatusError: Client error '403 Forbidden' for url 'https://api.example.com/v1/restricted'

- **ID:** `python/httpx-httperror-403-forbidden`
- **Domain:** python
- **Category:** auth_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The server denies access due to insufficient permissions, such as missing API key or IP whitelisting.

## Version Compatibility

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

## Workarounds

1. **Include the required API key in headers** (95% success)
   ```
   headers = {'Authorization': 'Bearer your-api-key'}
httpx.get('https://api.example.com/v1/restricted', headers=headers)
   ```
2. **Check if the IP address is whitelisted on the server** (80% success)
   ```
   import socket
my_ip = socket.gethostbyname(socket.gethostname())
print(my_ip)  # then verify with server admin
   ```

## Dead Ends

- **Re-sending the request without any authentication headers** — The server still requires valid credentials. (95% fail)
- **Using a different HTTP method (e.g., POST instead of GET)** — The issue is authorization, not method. (90% fail)
