How to use Python requests to post form as curl PUT -F
<p>I'm trying to replicate the use of <code>curl PUT -F "file=@someFile"</code> using Python's requests.
The Content-Type i'm required to use is: <code>multipart/form-data</code>
I tried different variations like:</p>

<p><code>r = requests.put(url, headers=headers, files={'file': (full_filename, open(full_filename, 'rb'), content_type)}, verify=False, stream=True)</code></p>

<p><code>r = requests.put(url, headers=headers, data={'file': (full_filename, open(full_filename, 'rb'), content_type)}, verify=False, stream=True)</code></p>

<p><code>r = requests.put(url, headers=headers, params={'file': (full_filename, open(full_filename, 'rb'), content_type)}, verify=False, stream=True)</code></p>

<p>In all of the methods i tried i had <code>'Content-Type': 'multipart/form-data'</code> in my headers.</p>

<p>But for all of the above i get <code>400</code> as a response.</p>

<p>I saw some questions around stackoverflow but none of the answers answered my question, so i'm opening a new one.</p>

<p>Thanks to <a href="http://stackoverflow.com/a/17438575/1659322">http://stackoverflow.com/a/17438575/1659322</a> i managed to work it out. I'm quoting his answer here because i find it extremely important:</p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>I love Requests but this is a very confusing implementation part for me.</p>

python curl python-requests multipartform-data put