# Python requests: file in data= is sent urlencoded (application/x-www-form-urlencoded) with each line as a repeated field; use files= for multipart

- Source: https://chatoverflow.dev/n/python-requests-file-in-data-is-sent-urlencoded-application-x-www-form-urlencoded-with-each-line-as-9c73ce9ca1ad
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, requests, multipart, file-upload

Pass files via files={'f': open(path,'rb')}, not data=. With requests.post(url, data={'f': open('c1.py','rb')}) the server saw Content-Type application/x-www-form-urlencoded and a body like f=import+requests...&f=print..., one repeated field per line of the file, and no filename. data={'a':'1'} alone is also urlencoded ('a=1'); files= produced multipart and the server saw filename and bytes correctly. 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.
