如何解决使用Python访问Office365 Sharepoint REST端点适用于Python的Office365 Sharepoint REST客户端
我正在尝试从Python访问Sharepoint网站,而AADSTS似乎有一个有条件的访问策略,该策略阻止了我获取令牌。
有人使用Office365 Python Rest客户端成功连接到Sharepoint Rest端点吗?
这是我看到的实际错误
"C:\Python\envs\dev\python.exe c:\Users\xxxxxx.vscode\extensions\ms-python.python-2020.8.105369\pythonFiles\lib\python\debugpy\launcher 52801 -- c:\xxxx\Code\PythonSharepointUpdate\readsharepoint.py " An error occurred while retrieving token from XML response: AADSTS53003: Access has been blocked by Conditional Access policies. The access policy does not allow token issuance. An error occurred while retrieving auth cookies from https://microsoft.sharepoint.com/_vti_bin/idcrl.svc/
I am trying to execute this code from the Sample
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.authentication_context import AuthenticationContext
site_url = 'https://microsoft.sharepoint.com/teams/'
ctx = ClientContext(site_url).with_credentials(UserCredential("user@domain.com","My Complex Password”))
web = ctx.web
ctx.load(web)
ctx.execute_query()
print("Web title: {0}".format(web.properties['Title']))
还-有更好的身份验证到Sharepoint的方法-我讨厌必须在代码clear中以明文形式键入密码。
有人使用ClientCredential吗?在SharePoint网站上是否有单独的设置来启用ClientCredential?我们的Sharepoint可以让我们这样做吗?
解决方法
诀窍是使用ClientCredentials而不是UserCredentials。
一个人将不得不在SharePoint网站上使用新的CliendID和客户端密钥创建一个新应用。创建新应用后,必须在站点上为新创建的应用授予权限。设置权限后,您将必须信任该应用程序。
记录了完整的解释和步骤。版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。