# httpx.HTTPStatusError: 对URL 'https://api.example.com/v1/process' 的服务器错误 '500 内部服务器错误'

- **ID:** `python/httpx-httperror-500-internal-server-error`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

服务器遇到意外情况，无法完成请求。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **Implement exponential backoff retry with a maximum number of attempts** (70% 成功率)
   ```
   import time
for i in range(3):
    try:
        response = httpx.get('https://api.example.com/v1/process')
        response.raise_for_status()
        break
    except httpx.HTTPStatusError as e:
        if e.response.status_code == 500:
            time.sleep(2 ** i)
        else:
            raise
   ```
2. **Contact the server administrator to investigate the issue** (90% 成功率)
   ```
   Review server logs for details on the 500 error.
   ```

## 无效尝试

- **Retrying the same request immediately** — Server-side errors often persist; retrying without delay may not help. (80% 失败率)
- **Modifying client-side headers arbitrarily** — The error is server-side; client headers rarely fix it. (90% 失败率)
