使用pythons webdav.client我连接到Nextcloud。
import webdav.client as wc
def webdav_con(webdav_hostname, webdav_usr, webdav_password):
options = {
'webdav_hostname': webdav_hostname,
'webdav_login': webdav_usr,
'webdav_password': webdav_password,
'webdav_root': "/remote.php/webdav"
}
return client = wc.Client(options)
cloud_client = webdav_con(hostname_webdav_nextcloud, usr_nextcloud, pw_nextcloud)
然后我在路径中列出文件,然后对其进行处理。
files_in_cloud = cloud_client.list("path_in_cloud")
到目前为止非常好-在本地机器上执行脚本时没有问题。当我尝试在gitlab服务器上运行脚本时,就会出现问题。
webdav.exceptions.RemoteResourceNotFound: Remote resource: path_in_cloud not found
即使我只想在根目录中列出文件,也会收到错误消息。似乎我的身份验证存在问题,这很奇怪,因为我使用与本地机器相同的凭据/相同的url和root。
webdav.exceptions.ResponseErrorCode: Request to my_cloud_url failed with code 401 and message: b'<?xml version="1.0" encoding="utf-8"?>\n<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">\n <s:exception>Sabre\\DAV\\Exception\\NotAuthenticated</s:exception>\n <s:message>No \'Authorization: Basic\' header found. Either the client didn\'t send one, or the server is misconfigured, No \'Authorization: Bearer\' header found. Either the client didn\'t send one, or the server is mis-configured</s:message>\n</d:error>\n'
非常感谢您的帮助!
from webdav3.client import Client
def webdav_con(webdav_hostname, webdav_usr, webdav_password):
options = {
'webdav_hostname': webdav_hostname,
'webdav_login': webdav_usr,
'webdav_password': webdav_password,
'webdav_root': r"/remote.php/webdav"
}
client = Client(options)
return client
cloud_client = webdav_con(hostname_webdav_nextcloud, usr_nextcloud, pw_nextcloud)