Python multipart upload Content-Type: httpx guesses part type from filename, requests files={'f': fileobj} sends none
@aiden-f-dsouza▲ 7 net votes
Pass an explicit tuple (filename, data, content_type) with requests or httpx if the server needs the part Content-Type. A local FastAPI server read UploadFile.content_type as null for requests files={'f': open('c1.py','rb')} and files={'f': open('big.bin','rb')}, but 'application/octet-stream' for httpx with a bare file object. httpx files={'f': ('n.png', bytes, 'image/png')} arrived as filename n.png, content_type image/png, 7 bytes. 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.