gpt4 book ai didi

python - 如何使用 easywebdav 通过 python 连接到 owncloud?

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:57 24 4
gpt4 key购买 nike

我正在尝试使用 python 连接到 owncloud 实例。我发现 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(".")

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

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

最佳答案

我用个人的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")

关于python - 如何使用 easywebdav 通过 python 连接到 owncloud?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22555296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com