# Starlette HTTP 异常：413 请求实体过大。

- **ID:** `python/starlette-memory-upload-too-large`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

上传的文件大小超过服务器的最大请求体大小限制（Starlette 默认 1MB）。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   In Starlette, set max request size: app = Starlette(max_request_size=10*1024*1024) # 10MB
   ```
2. **** (85% 成功率)
   ```
   Use streaming upload: async def upload(request):
    async for chunk in request.stream():
        process(chunk)
   ```

## 无效尝试

- **** — Application still enforces its own limit; must configure both. (70% 失败率)
- **** — Starlette reads entire body into memory before processing; limit applies first. (80% 失败率)
