I need to create a small WebDAV client that just upload files on the server.
I’ve found “requests” library that seems to be very easy to be used but I’m not able to use it properly.
The client should transfer binary files – so I’ve used the example bellow:
>>> url = 'http://IPADDR/webdav'
>>> files = {'report.xls': open('report.xls', 'rb')}
>>> r = requests.post(url, files=files)
from http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file.
For me it’s not working, I have the following error:
File ".../site-packages/requests/packages/urllib3/connectionpool.py", line 260, in _make_request
conn.request(method, url, **httplib_request_kw)
File ".../httplib.py", line 941, in request
self._send_request(method, url, body, headers)
File ".../httplib.py", line 975, in _send_request
self.endheaders(body)
File ".../httplib.py", line 937, in endheaders
self._send_output(message_body)
File ".../httplib.py", line 795, in _send_output
msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 147: ordinal not in range(128)
Should be the input file somehow encoded? (I didn’t found anything related in the “requests” documentation).
After some debugging, I’ve actually found what’s happening.
I was able to fix the issue by removing the following import in my script:
This import seems to cause unwanted string conversions in urllib3 (which requests relies on).
As requests’ author explained, this issue should be filed against urllib3.