$ curl -F myfile=@myfilename -F 'data={"title":"some title","otherinfo" : "aabcdef"}' https://someurl
The above is the working and correct way for doing from terminal.
I tried to implement this in python using requests in this way :
files = {'myfile': open('myfilename', 'rb')}
data = {}
data['data'] = {
'title' : 'some title',
'otherinfo' : 'other info'
}
r = requests.post(url, files=files, data=data, auth=auth)
Here, the data is not reaching the destination properly, where am I wrong ?
When you use
-Fargument curl sends data withContent-Typeset tomultipart/form-datawhereas when you usedataparameter Requests usesContent-Typeset toapplication/x-www-form-urlencoded. You should instruct Requests to send data with the rightContent-Type. See How to send a "multipart/form-data" with requests in python? how to do this.