I'm trying to replicate the use of curl PUT -F "file=@someFile"
using Python's requests.
The Content-Type i'm required to use is: multipart/form-data
I tried different variations like:
r = requests.put(url, headers=headers, files={'file': (full_filename, open(full_filename, 'rb'), content_type)}, verify=False, stream=True)
r = requests.put(url, headers=headers, data={'file': (full_filename, open(full_filename, 'rb'), content_type)}, verify=False, stream=True)
r = requests.put(url, headers=headers, params={'file': (full_filename, open(full_filename, 'rb'), content_type)}, verify=False, stream=True)
In all of the methods i tried i had 'Content-Type': 'multipart/form-data'
in my headers.
But for all of the above i get 400
as a response.
I saw some questions around stackoverflow but none of the answers answered my question, so i'm opening a new one.
Thanks to https://stackoverflow.com/a/17438575/1659322 i managed to work it out. I'm quoting his answer here because i find it extremely important:
You should NEVER set that header yourself. We set the header properly with the boundary. If you set that header, we won't and your server won't know what boundary to expect (since it is added to the header). Remove your custom Content-Type header and you'll be fine.
I love Requests but this is a very confusing implementation part for me.