5

I'm trying to connect to a owncloud instance with python. I've found easywebdav that should make it easy to connect via webdav, but when trying to connect I'm getting "404 Not Found"

import easywebdav
webdav = easywebdav.connect('test.org/owncloud/remote.php/webdav/', username='user', password='pass', protocol='https', port=443, verify_ssl=False)
print webdav.ls(".")

I would expect a list of files found on my owncloud instance, but I'm getting

python ./test.py 
Traceback (most recent call last):
File "./test.py", line 8, in <module>
    print webdav.ls(".")
File "/usr/lib/python2.7/site-packages/easywebdav-1.0.7-py2.7.egg/easywebdav/client.py", line 131, in ls
    response = self._send('PROPFIND', remote_path, (207, 301), headers=headers)
File "/usr/lib/python2.7/site-packages/easywebdav-1.0.7-py2.7.egg/easywebdav/client.py", line 81, in _send
    raise OperationFailed(method, path, expected_code, response.status_code)
easywebdav.client.OperationFailed: Failed to list directory ".".
Operation     :  PROPFIND .
Expected code :  207 UNKNOWN, 301 Moved Permanently
Actual code   :  404 Not Found

What I find weird, is that if I connect to a invalid path, with

webdav = easywebdav.connect('test.org/owncloud-not-existent/', ......)

I get

Traceback (most recent call last):
File "./test.py", line 8, in <module>
    print webdav.ls(".")
File "/usr/lib/python2.7/site-packages/easywebdav-1.0.7-py2.7.egg/easywebdav/client.py", line 131, in ls
    response = self._send('PROPFIND', remote_path, (207, 301), headers=headers)
File "/usr/lib/python2.7/site-packages/easywebdav-1.0.7-py2.7.egg/easywebdav/client.py", line 81, in _send
    raise OperationFailed(method, path, expected_code, response.status_code)
easywebdav.client.OperationFailed: Failed to list directory ".".
Operation     :  PROPFIND .
Expected code :  207 UNKNOWN, 301 Moved Permanently
Actual code   :  405 Method Not Allowed
Ian Stapleton Cordasco
  • 26,944
  • 4
  • 67
  • 72
Quamis
  • 10,924
  • 12
  • 50
  • 66

3 Answers3

3

I've tested with a personal WebDav server and I found a similar issue, although I think that my easywebdav version is different, I use v1.0.7 and the parameter verify_ssl is not allowed, so I did the test with "http".

Anyway, I got to reproduce your issue, to fix it change the connection url and use only the host, putting the path in the ls() command :

import easywebdav
webdav = easywebdav.connect('test.org', username='user', password='pass', protocol='https', port=443, verify_ssl=False)
print webdav.ls("/owncloud/remote.php/webdav")
Roberto
  • 8,586
  • 3
  • 42
  • 53
  • 1
    thx, it works. for the ssl issue, i used the patch from https://github.com/amnong/easywebdav/pull/12 – Quamis Mar 21 '14 at 10:12
  • 1
    @Quamis when using a self-signed certficate in private production consider adding it to your clients trusted CA's. It beats skipping verification, hands down. – Chris Wesseling Mar 21 '14 at 10:28
  • @ChrisWesseling how can i do that? I'm using fedora here – Quamis Mar 21 '14 at 10:43
  • @Quamis Download the certificate in pem format. And check its correctness! Then append it to the bundle of trusted certificates that lives either in /etc/ssl/certs or in /etc/pki. On most distro's you can do it on a per user basis in $HOME/.pki too. – Chris Wesseling Mar 21 '14 at 12:10
  • @ChrisWesseling: how can i do that? I saved the certificate in PEM format by issuing page info in firefox, and exporting it. By simply adding it to $HOME/.pki it seems that the host is still not trusted. Do i have to do something more? – Quamis May 20 '14 at 13:20
  • @Quamis thats a bit to much for a comment. See [this question](http://stackoverflow.com/q/23767304/383793) – Chris Wesseling May 20 '14 at 18:30
1

While the solution in the previous answer does work around the issue, it's less convenient to have to pass in the path on each command.

Digging deeper, it appears that owncloud simply doesn't support paths with '.' on the end. easywebdav actually has a default path of '.' for commands like ls() such that doing webdav.ls() should print the current directory, but as seen above you get an error instead.

Simply calling ls with a complete path works fine though, which is why the suggested answer above worked.

A simpler solution to the original question is:

import easywebdav
webdav = easywebdav.connect('test.org/owncloud/remote.php/webdav/', username='user', password='pass', protocol='https', port=443, verify_ssl=False)
print webdav.ls("/")
coronafire
  • 17
  • 1
  • 9
-1
connection = easywebdav.connect( 'something.tld',
                    username   = 'your_username',
                    password   = 'your_password',
                    protocol   = 'https',
                    path       = 'owncloud/remote.php/webdav',
                    verify_ssl = False) #not commended
connection.cd("my_folder")
connection.ls("") # Seafile's seafdav will return a 404 if you use the "." or ".." directory
Facundo
  • 131
  • 1
  • 8