由于证书问题,从Python连接到SharePoint Online时面临问题

2024-09-29 23:32:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从SharePoint到Python获取列表项,下面是我用于poc的代码

ctx_auth = AuthenticationContext(url='https://SharePointSiteURL')
if ctx_auth.acquire_token_for_user(username='MyUser@Company.onmicrosoft.com',password='MyPassword'):
ctx = ClientContext('https://SharePointSiteURL', ctx_auth)
lists = ctx.web.lists
ctx.load(lists)

我得到的问题如下错误 “错误:HTTPSConnectionPool(host='login.microsoftonline.com',port=443):url:/GetUserRealm.srf超过了最大重试次数(由SSLError引起(SSLCertVerificationError(1),[SSL:CERTIFICATE\u Verification\u FAILED]CERTIFICATE Verification FAILED:无法获取本地颁发者证书(\u SSL.c:1076))”

我正在尝试设置ssl verify=none以使poc移动,有没有关于如何使用AuthenticationContext实现这一点的想法

多谢各位 内特


Tags: httpscomauthurlssl错误certificatelists
1条回答
网友
1楼 · 发布于 2024-09-29 23:32:11

在最新版本中,公开了RequestOptions.verify属性,该属性允许:

to control whether to verify the server's TLS certificate which accepts:

  • boolean value (defaults to True)
  • string value, which represents path to a CA bundle to use

示例

可以通过底层HTTP请求对象禁用证书验证,如下所示:

def disable_ssl(request):
    request.verify = False  # Disable certification verification


ctx = ClientContext.connect_with_credentials("https://contoso.sharepoint.com",
                                             UserCredential(username,
                                                            password)

ctx.get_pending_request().beforeExecute += disable_ssl
web = ctx.web
ctx.load(web)
ctx.execute_query()
print(web.properties["Url"])

注意

一旦被禁用,urllib3可能会抱怨^{} warning,这是由于向主机发出了未经验证的HTTPS请求 {tenant}.sharepoint.com。强烈建议添加证书验证

安装

因为它需要最新版本,所以可以从GitHub安装(直到在PyPI中发布):

pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git

相关问题 更多 >

    热门问题