python
runtime_error
ai_generated
true
Starlette 异常:413:请求实体过大
starlette.exceptions.HTTPException: 413: Request Entity Too Large
ID: python/starlette-upload-file-size-limit
80%修复率
84%置信度
0证据数
2025-02-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
上传的文件超过服务器配置中设置的最大上传大小限制。
English
Uploaded file exceeds the maximum upload size limit set in the server configuration.
解决方案
-
70% 成功率
Set a custom limit in uvicorn: uvicorn.run(app, limit_max_request_size=1000000) for 1MB
-
90% 成功率
Use a middleware to check content-length and reject early with a custom message
无效尝试
常见但无效的做法:
-
80% 失败
Uvicorn doesn't have a direct setting; you need to configure the ASGI server or use a middleware.
-
50% 失败
This handles the error but doesn't allow the upload; you need to increase the limit.