Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set filename on Post with python requests

I want to set the name of a file I'm uploading via requests module.

files = {'filename': open('myfileXXAAAZZZD','rb')}
r = requests.post("http://127.0.0.1:5000/", files=files)

It is possible with curl but don't know if requests support's this:

like image 359
user1767754 Avatar asked Jan 02 '23 15:01

user1767754


1 Answers

As stated in the docs, the values of the files dict can be tuples with filename and content as the first of possibly more elements. So something like

files = {'fieldname': ('filename.any', open('myfileXXAAAZZZD','rb').read())}

should do the trick.

like image 81
user2390182 Avatar answered Jan 05 '23 15:01

user2390182