HTTP-Post with Requests fails: BadStatusLine
<p>I got a problem with the following code. While trying to upload a file to the API using a POST-Request I get an error saying</p>
<pre><code>File &quot;upload.py&quot;, line 44, in &lt;module&gt;
    so.uploadData(&quot;./test.txt&quot;)
  File &quot;upload.py&quot;, line 37, in uploadData
    req = requests.post(&quot;http://&quot;+server, data=payload, headers=headers)
  File &quot;/Library/Python/2.7/site-packages/requests/api.py&quot;, line 109, in post
    return request('post', url, data=data, json=json, **kwargs)
  File &quot;/Library/Python/2.7/site-packages/requests/api.py&quot;, line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File &quot;/Library/Python/2.7/site-packages/requests/sessions.py&quot;, line 468, in request
    resp = self.send(prep, **send_kwargs)
  File &quot;/Library/Python/2.7/site-packages/requests/sessions.py&quot;, line 576, in send
    r = adapter.send(request, **kwargs)
  File &quot;/Library/Python/2.7/site-packages/requests/adapters.py&quot;, line 412, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine(&quot;''&quot;,))
</code></pre>
<p>My Code looks like this:</p>
<pre class="lang-py prettyprint-override"><code>filedata= open(path, 'r')
payload = {'name': self.username, 'file':filedata}
headers = {
  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36',
  'content-type': &quot;multipart/form-data&quot;}
req = requests.post(&quot;http://&quot;+server, data=payload, headers=headers)
</code></pre>
<p>Does anyone have a solution for this problem? Best regards</p>