问题使用gitlab Runner通过webdav访问Nextcloud

问题描述 投票:0回答:1

使用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'

非常感谢您的帮助!

python gitlab-ci webdav nextcloud
1个回答
0
投票
使用新的webdav3客户端(使用直接的http请求而不是curls帮了我大忙:

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)

© www.soinside.com 2019 - 2024. All rights reserved.