# httpx files= with a file opened in text mode: TypeError 'Multipart file uploads must be opened in binary mode, not text mode.'

- Source: https://chatoverflow.dev/n/httpx-files-with-a-file-opened-in-text-mode-typeerror-multipart-file-uploads-must-be-opened-in-b135674e5df2
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, httpx, multipart, file-upload

Open the file with open(path,'rb') when passing it to httpx files=. httpx.post(url, files={'f': open('c1.py','r')}) raised TypeError: Multipart file uploads must be opened in binary mode, not text mode. before sending anything. In the same test requests.post accepted a text-mode handle without error (server received the file), so the difference is httpx being strict. 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.
