[英]Accessing Office365 Sharepoint REST EndPoints using Python (Office365 Sharepoint REST client for Python)
I am trying to get access to a Sharepoint site from Python and it seems like AADSTS has a conditional access policy that's preventing me from getting a token.我正在尝试从 Python 访问 Sharepoint 站点,似乎 AADSTS 有条件访问策略阻止我获取令牌。
Has anyone used the Office365 Python Rest Client to successful connect to a Sharepoint Rest Endpoint?有没有人使用 Office365 Python Rest 客户端成功连接到 Sharepoint Rest 端点?
This is the actual error I am seeing这是我看到的实际错误
"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']))
Also – is there a better way to authenticate to Sharepoint – I hate to have to type my Password in clear text in code ☹另外——有没有更好的方法来验证 Sharepoint——我讨厌在代码中以明文形式输入我的密码☹
Has anyone use ClientCredential?有人用过 ClientCredential 吗? Is there a seperate setup on the Sharepoint Site to enable ClientCredential?
Sharepoint 站点上是否有单独的设置来启用 ClientCredential? Does our Sharepoint let us do that?
我们的 Sharepoint 让我们这样做吗?
The trick is to use ClientCredentials and not UserCredentials.诀窍是使用 ClientCredentials 而不是 UserCredentials。
One will have to create a new app on the Sharepoint site with a new CliendID and Client Secret.必须在 Sharepoint 站点上使用新的 CliendID 和 Client Secret 创建一个新的应用程序。 After creating a new app, the newly created app has to be given permissions on the site.
创建新应用程序后,必须为新创建的应用程序授予网站权限。 Once the permissions are set, you will have to Trust the app.
设置权限后,您将必须信任该应用程序。
The full explanation and the steps are documented here https://github.com/vgrem/Office365-REST-Python-Client/wiki/How-to-connect-to-SharePoint-Online-and-and-SharePoint-2013-2016-2019-on-premises--with-app-principal完整的解释和步骤记录在此处https://github.com/vgrem/Office365-REST-Python-Client/wiki/How-to-connect-to-SharePoint-Online-and-and-SharePoint-2013-2016 -2019-on-premises--with-app-principal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.