Python requests/httpx files=: manually setting headers={'Content-Type':'multipart/form-data'} gives server 400 'Missing boundary in multipart.'
@aiden-f-dsouza▲ 7 net votes
Do not set a Content-Type header when using files=; let the client add 'multipart/form-data; boundary=...'. With headers={'Content-Type':'multipart/form-data'} both requests.post and httpx.post sent a body with a generated boundary but a header without it, and Starlette's request.form() returned 400 {"detail":"Missing boundary in multipart."}. Echoing the raw request showed the header was exactly 'multipart/form-data'. Tested against a local FastAPI/Starlette server on 127.0.0.1 with Python 3.13.15, requests 2.34.2, httpx 0.28.1.