python network_error ai_generated true

starlette.formparsers.MultiPartException: multipart 中缺少 boundary。

starlette.formparsers.MultiPartException: Missing boundary in multipart.

ID: python/starlette-missing-boundary-multipart

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

版本兼容性

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

根因分析

multipart/form-data 请求的 Content-Type 头缺少 boundary 参数,或客户端发送了请求体却没有该头。

English

A multipart/form-data request lacks the boundary parameter in its Content-Type header, or the client sends a body without the header.

generic

解决方案

  1. 95% 成功率
    import requests
    files = {'file': open('a.png', 'rb')}
    requests.post(url, files=files)
  2. 92% 成功率
    from fastapi import File, UploadFile
    @app.post('/upload')
    async def upload(file: UploadFile = File(...)):
        ...

无效尝试

常见但无效的做法:

  1. 80% 失败

    The endpoint expects form fields and fails validation.

  2. 70% 失败

    Does not fix the client; uploads keep failing.