title: POST Binary (video) File Using Python Requests
body: <p>I have a working bit of PHP code that uploads a binary to a remote server I don't have shell access to. The PHP code is:</p>
  
  <pre class="lang-php prettyprint-override"><code>function upload($uri, $filename) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $uri);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' =&gt; '@' . $filename));
  curl_exec($ch);
  curl_close($ch);
  }
  </code></pre>
  
  <p>This results in a header like:</p>
  
  <pre><code>HTTP/1.1
  Host: XXXXXXXXX
  Accept: */*
  Content-Length: 208045596
  Expect: 100-continue
  Content-Type: multipart/form-data; boundary=----------------------------360aaccde050
  </code></pre>
  
  <p>I'm trying to port this over to python using requests and I cannot get the server to accept my POST. I have tried every which way to use requests.post, but the header will not mimic the above.</p>
  
  <p>This will successfully transfer the binary to the server (can tell by watching wireshark) but because the header is not what the server is expecting it gets rejected. The response_code is a 200 though.</p>
  
  <pre><code>files = {'bulk_test2.mov': ('bulk_test2.mov', open('bulk_test2.mov', 'rb'))}
  response = requests.post(url, files=files)
  </code></pre>
  
  <p>The requests code results in a header of:</p>
  
  <pre><code>HTTP/1.1
  Host: XXXX
  Content-Length: 160
  Content-Type: multipart/form-data; boundary=250852d250b24399977f365f35c4e060
  Accept-Encoding: gzip, deflate, compress
  Accept: */*
  User-Agent: python-requests/2.2.1 CPython/2.7.5 Darwin/13.1.0
  
  --250852d250b24399977f365f35c4e060
  Content-Disposition: form-data; name="bulk_test2.mov"; filename="bulk_test2.mov"
  
  
  --250852d250b24399977f365f35c4e060--
  </code></pre>
  
  <p>Any thoughts on how to make requests match the header that the PHP code generates?</p>