python network_error ai_generated true

starlette.formparsers.MultiPartException: Missing boundary in multipart.

ID: python/starlette-missing-boundary-multipart

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-06-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 80% fail

    The endpoint expects form fields and fails validation.

  2. 70% fail

    Does not fix the client; uploads keep failing.