# 运行时错误：响应内容长度超过 Content-Length

- **ID:** `python/starlette-response-content-length`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

响应体大小与 Content-Length 头不匹配，通常是由于手动设置头导致。

## 版本兼容性

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

## 解决方案

1. **** (100% 成功率)
   ```
   Don't set Content-Length manually; let Response handle it: return Response(content=body)
   ```
2. **** (90% 成功率)
   ```
   If you must set it, compute len(body) and set header accordingly
   ```

## 无效尝试

- **** — If the body changes, the length becomes stale; better to let Starlette compute it. (80% 失败率)
- **** — Starlette may still check; you need to ensure the stream sends exactly the right bytes. (60% 失败率)
