【问题标题】:Problems accessing Nextcloud via webdav with gitlab runner使用 gitlab runner 通过 webdav 访问 Nextcloud 的问题
【发布时间】:2020-03-30 08:17:46
【问题描述】:

使用 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】:

    'webdav_root'中有一个拼写错误:r"/remote.php/webdav",去掉'r'使其生效。

    【讨论】:

      【解决方案2】:

      我自己设法解决了这个问题。 webdavclient 如何在后台处理请求似乎存在问题。

      使用新的 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)
      

      【讨论】: