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

- **ID:** `python/starlette-upload-file-size-limit`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

上传的文件超过服务器配置中设置的最大上传大小限制。

## 版本兼容性

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

## 解决方案

1. **** (70% 成功率)
   ```
   Set a custom limit in uvicorn: uvicorn.run(app, limit_max_request_size=1000000) for 1MB
   ```
2. **** (90% 成功率)
   ```
   Use a middleware to check content-length and reject early with a custom message
   ```

## 无效尝试

- **** — Uvicorn doesn't have a direct setting; you need to configure the ASGI server or use a middleware. (80% 失败率)
- **** — This handles the error but doesn't allow the upload; you need to increase the limit. (50% 失败率)
