title: Python requests.post multipart/form-data
body: <p>I have to use a REST API to upload files and information to a server. That API uses a multipart-form, but I cannot seem to be able to use it correctly.</p>
  
  <p>Here is the information I use according to the API documentation.</p>
  
  <p>Form Parameters:</p>
  
  <ul>
  <li>description – A short description of the distribution.</li>
  <li>release_notes_url – A url pointing to the release notes.</li>
  <li>zip_file – The ZIP file containing the distribution files.</li>
  </ul>
  
  <p>Example request:</p>
  
  <pre><code>POST /api/v1/distribution HTTP/1.1
  Host: api.company.onbe
  Authorization: t=...
  Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryZayrf7leHxinyQsX
  
  
  ------WebKitFormBoundaryZayrf7leHxinyQsX
  Content-Disposition: form-data; name="release_notes_url"
  http://releases/3.0.0/release_notes_3_0_0.pdf
  ------WebKitFormBoundaryZayrf7leHxinyQsX
  Content-Disposition: form-data; name="description"
  This is the new distribution!
  ------WebKitFormBoundaryZayrf7leHxinyQsX
  Content-Disposition: form-data; name="zip_file"; filename="BackEnd-3.0.0.zip"
  Content-Type: application/x-zip-compressed
  ------WebKitFormBoundaryZayrf7leHxinyQsX--
  </code></pre>
  
  <p>I tried several things, like the following code for example, but I keep getting bad request errors from the server.</p>
  
  <pre><code>import requests
  
  file= open('BackEnd-3.0.0.zip','r').read()
  
  url = 'api.company.onbe/api/v1/distribution'
  
  payload = {
    'description' :'Some desc',
    'release_notes_url':'Someurl.pdf',
    'zip_file': file
    }
  
  response = requests.post(url, data=payload)
  </code></pre>