title: Sending a unencoded multipart/form-data POST request of files and metadata using python
body: <p>I am trying to upload several files and some metadata through a POST to a server API using python and requests. I want to use the multipart/form-data type and not encode the data.
  I've followed the steps according to tutorials and the requests documentation, but run into several issues:</p>
  <pre><code>import requests
  
  data = {
      &quot;key1&quot;: &quot;value1&quot;,
      &quot;key2&quot;: &quot;value2&quot;
  }
  
  files = {
      &quot;image&quot;: open('image.jpg', 'rb')
  }
  
  headers = {
      &quot;accept&quot;: &quot;*/*&quot;,
      &quot;Authorization&quot;: &quot;Bearer &quot; + token
      &quot;Content-Type&quot;: &quot;multipart/form-data; boundary=----WebKitFormBoundaryzqgQ4h5D6Zi8&quot;
  }
  
  r = requests.post(url, files=files, data=data, headers=headers, verify=False)
  print(r.status_code, r.text)
  </code></pre>
  <p>This gets me a 400 and the error:</p>
  <p><code>&quot;Failed to read the request form. Multipart body length limit 16384 exceeded.&quot;</code></p>
  <p>I read that what might help is to leave the Content-Type to requests and it will figure it out.
  Without the Content-Type declaration I still get a 400 and a the text back:</p>
  <p><code>file is required</code></p>
  <p>Now this might be a server-side issue (which I have no see over), since it demands multipart/form-data, but I suppose requests deals with the correct identification?</p>
  <p>So far I'm out of luck, does anyone have an idea how to solve this?</p>
  <hr />
  <p><strong>EDIT</strong>: still don't know what exactly causes the issue, but found a workaround:</p>
  <ul>
  <li>added all the data directly to the URL string</li>
  <li>eliminated all the headers but the necessary Authorization token</li>
  </ul>
  <p>It seems to me that requests is able to do a lot of the heavy lifting and too much declarations get in the way (?).</p>