5

我正在尝试owncloud使用 python 连接到一个实例。我发现easywebdav应该可以很容易地通过 webdav 进行连接,但是在尝试连接时我得到“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(".")

我希望在我自己的云实例上找到一个文件列表,但我得到了

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

我觉得奇怪的是,如果我连接到无效路径,使用

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

我明白了

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
4

3 回答 3

3

我用个人的WebDav服务器测试过,也发现了类似的问题,虽然我觉得我的easywebdav版本不一样,我用的是v1.0.7,参数verify_ssl是不允许的,所以我用“http”做了测试。

无论如何,我必须重现您的问题,修复它更改连接 url 并仅使用主机,将路径放在ls()命令中:

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")
于 2014-03-21T10:08:38.663 回答
1

虽然上一个答案中的解决方案确实解决了这个问题,但必须在每个命令上传递路径不太方便。

深入挖掘,owncloud 似乎根本不支持带有 '.' 的路径。最后。easywebdav 实际上有一个默认路径“。” 对于像 ls() 这样的命令,执行 webdav.ls() 应该打印当前目录,但如上所示,您会得到一个错误。

不过,只需使用完整路径调用 ls 就可以了,这就是上面建议的答案有效的原因。

原始问题的一个更简单的解决方案是:

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("/")
于 2016-03-02T11:54:39.967 回答
-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
于 2016-08-10T16:32:31.620 回答