amnong / easywebdav

A WebDAV Client in Python
http://pypi.python.org/pypi/easywebdav/
ISC License
207 stars 113 forks source link

HEAD returns a 301 for exists function when directory exists #21

Closed kartoch closed 10 years ago

kartoch commented 10 years ago

I've the following error stack:

Traceback (most recent call last):
  File "/home/kartoch/Documents/works/web/www/tasks.py", line 56, in publish
    print(webdav.exists(remote_path))
  File "/home/kartoch/opt/python/pelican/src/easywebdav/easywebdav/client.py", line 178, in exists
    response = self._send('HEAD', remote_path, (200, 404))
  File "/home/kartoch/opt/python/pelican/src/easywebdav/easywebdav/client.py", line 98, in _send
    raise OperationFailed(method, path, expected_code, response.status_code)
easywebdav.client.OperationFailed: Failed to head "resources".
  Operation     :  HEAD resources
  Expected code :  200 OK, 404 Not Found
  Actual code   :  301 Moved Permanently

The problem seems that the webdav server is returning a 301 when method exists() check for existing directory, and easywebdav is expecting a 200 or 404.

kartoch commented 10 years ago

I could force the method _send to accept 301:

 self._send('HEAD', remote_path, (200, 301, 404))

But I'm not sure if it is the right way / coherent with the webdav procotol.

amnong commented 10 years ago

I'm also unsure...

kartoch commented 10 years ago

It seems the '301' case is managed by the ls and mkdir commands. Maybe factorize the code about this case then extends exists for it ?

kartoch commented 10 years ago

usually redirection could be manage by requests. Why not put a switch to activate it globaly and/or for each function as optional parameter ? The programmer will choose if it is acceptable to redirect or not.

amnong commented 10 years ago

Well @kartoch, I'm not sure WebDAV 301 should actually be treated as a redirection. The protocol is a bit unclear to me, to be honest. I just change and fix stuff according to comments of developers who use this library.

So anyway, yes - we can just add this code to the expected codes I guess. I'm personally against turning on automatic redirections in requests because I'm not sure whether or not it makes sense. If you try that yourself and find that it works as expected, please let me know what you tested and how, and submit a pull request.

amnong commented 10 years ago

Added 301 to expected result of exists().