python network_error ai_generated true

fastapi.exceptions.HTTPException: 413:请求实体过大

fastapi.exceptions.HTTPException: 413: Request Entity Too Large

ID: python/fastapi-file-upload-too-large

其他格式: JSON · Markdown 中文 · English
80%修复率
83%置信度
0证据数
2024-09-27首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

上传文件超过服务器或反向代理的请求体大小限制(如 nginx client_max_body_size)。

English

The uploaded file exceeds the server or reverse proxy body size limit (e.g. nginx client_max_body_size).

generic

解决方案

  1. 92% 成功率
    client_max_body_size 50m;
  2. 85% 成功率
    async for chunk in request.stream():
        await save_chunk(chunk)

无效尝试

常见但无效的做法:

  1. 90% 失败

    FastAPI has no built-in limit; the block is at nginx/gunicorn.

  2. 85% 失败

    Same payload will always exceed the limit.