简体   繁体   English

使用 Python 访问 Office365 Sharepoint REST 端点(Python 的 Office365 Sharepoint REST 客户端)

[英]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.

相关问题 在sharepoint office365 REST Python 客户端上传不同大小的文件 - Uploading files of different sizes on sharepoint office365 REST Python Client 使用 Office365-REST-Python-Client 复制 Sharepoint 中的文件 - Copy file in Sharepoint using Office365-REST-Python-Client 通过 Python office365 API 下载 Sharepoint Docx 文件 - Download Sharepoint Docx file via Python office365 API 通过 Python 单点登录访问 Office365 SharePoint - Access Office365 SharePoint with Single Sign-On via Python Using Python to access Excel File on Sharepoint using Office365 Python Module - Using Python to access Excel File on Sharepoint using Office365 Python Module SharePoint 在线:使用 Office365-REST-Python-Client 库获取站点用户 ID - SharePoint online: Get site user id using Office365-REST-Python-Client library 如何使用工作或学校帐户将 SharePoint Online (Office365) Excel 文件读取到 Python 特别是 pandas? - How to read SharePoint Online (Office365) Excel files into Python specifically pandas with Work or School Account? 如何使用工作或学校帐户在 Python 中阅读 SharePoint Online (Office365) Excel 文件? - How to read SharePoint Online (Office365) Excel files in Python with Work or School Account? 如何将文件夹及其内容复制到 SharePoint 中的新位置 python office365 模块在线 - How to copy folder and its content into new location in SharePoint Online with python office365 module 使用 office365 API 将文件上传到 Sharepoint 中的子文件夹 - Upload file to a subfolder in Sharepoint with office365 API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM