owncloud / pyocclient

ownCloud client library for Python
MIT License
295 stars 115 forks source link

Error on put_file (Header) #176

Closed Atheryl closed 8 years ago

Atheryl commented 8 years ago

Hi,

The library sounds amazing but I'm stuck with an issue while trying to upload something (Both put_file and put_directory)

requests.exceptions.InvalidHeader: Header value 1475201477.79 must be of type str or bytes, not <type 'float'>

The full stack :

Traceback (most recent call last): File "/var/opt/.../Scripts/utils.py", line 104, in storeOnOwnCloud oc.put_file("/Billing/", "/var/opt/.../file-2016-08.xlsx") File "/usr/lib/python2.7/site-packages/owncloud/owncloud.py", line 495, in put_file _kwargs File "/usr/lib/python2.7/site-packages/owncloud/owncloud.py", line 605, in put_file_chunked headers=headers File "/usr/lib/python2.7/site-packages/owncloud/owncloud.py", line 1649, in make_dav_request _kwargs File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 461, in request prep = self.prepare_request(req) File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 394, in prepare_request hooks=merge_hooks(request.hooks, self.hooks), File "/usr/lib/python2.7/site-packages/requests/models.py", line 295, in prepare self.prepare_headers(headers) File "/usr/lib/python2.7/site-packages/requests/models.py", line 409, in prepare_headers check_header_validity(header) File "/usr/lib/python2.7/site-packages/requests/utils.py", line 800, in check_header_validity "not %s" % (value, type(value))) requests.exceptions.InvalidHeader: Header value 1475201477.79 must be of type str or bytes, not <type 'float'>

Running on Centos 7, python 2.7

PVince81 commented 8 years ago

Can you tell me the exact file size in bytes of file-2016-08.xlsx ? Could be related to https://github.com/owncloud/pyocclient/issues/175

Atheryl commented 8 years ago

It's a pretty small file below 50 KB.

I can try the fix about Thursday to confirm.

PVince81 commented 8 years ago

hmm, but the header says 1475201477.79 which sounds like 1 TB, weird

Atheryl commented 8 years ago

I think that's a timestamp

Timestamp Converter 1475201477.79 Is equivalent to:

09/30/2016 @ 2:11am (UTC) 2016-09-30T02:11:17+00:00 in ISO 8601

Fri, 30 Sep 2016 02:11:17 +0000 in RFC 822, 1036, 1123, 2822

Friday, 30-Sep-16 02:11:17 UTC in RFC 2822

2016-09-30T02:11:17+00:00 in RFC 3339

PVince81 commented 8 years ago

Ah, indeed. I guess it might be the OC-MTime header.

So the code needs to be fixed to remove the decimal places I guess.

Atheryl commented 8 years ago

I think so, but I haven't get much time to dig into where this take places.

bobatsar commented 8 years ago

Hi there, I just had the same issue and it is related to requests 2.11.1.

Temporarily you can revert back to requests 2.10.0 with e.g. pip install requests==2.10.0

Perhaps this link clarifies the issue a little bit more: http://peichengnote.blogspot.de/2016/09/python-requestsutilspy-line-800-in.html

PVince81 commented 8 years ago

Thanks. So if I understand correctly the values for headers need to be converted to string every time ? This would be likely to be backwards compatible.

I'm not sure when I'll have time to look into this, so if you guys have time, feel free to submit a PR.

PVince81 commented 8 years ago

This is already fixed on master apparently https://github.com/owncloud/pyocclient/commit/8de5d392156afc56be3600aab1cd1758d7c877c0 through python3 support, the fix will be in 0.3

PVince81 commented 7 years ago

Seems there is more to it: https://github.com/owncloud/pyocclient/issues/190

Maybe some Python versions return float values for the timestamp?