'HTTP-Post with Requests fails: BadStatusLine
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
File "upload.py", line 44, in <module>
so.uploadData("./test.txt")
File "upload.py", line 37, in uploadData
req = requests.post("http://"+server, data=payload, headers=headers)
File "/Library/Python/2.7/site-packages/requests/api.py", line 109, in post
return request('post', url, data=data, json=json, **kwargs)
File "/Library/Python/2.7/site-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/Library/Python/2.7/site-packages/requests/adapters.py", line 412, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine("''",))
My Code looks like this:
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': "multipart/form-data"}
req = requests.post("http://"+server, data=payload, headers=headers)
Does anyone have a solution for this problem? Best regards
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
