我试图从SharePoint中提取一个文件并将其复制到一个S3桶中。我有一个使用用户名和密码的代码,但是我被要求将我的方法更改为oauth2。起作用的旧代码:
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.client_context import ClientCredential
SP_SITE_URL ='https://companyname.sharepoint.com/sites/sitename'
userID= config["sharepoint"]["userID"]
password= config["sharepoint"]["password"]
client_credentials = ClientCredential(userID, password)
ctx = ClientContext(SP_SITE_URL).with_user_credentials(userID,password)
file_url = FOLDER_URL + current_file_name
response = File.open_binary(ctx, file_url)我试图将凭证转换为clientID和Clientsecrent:
client_id = config["sharepoint"]["clientID"]
client_secret = config["sharepoint"]["client_secret"]
client_credentials = ClientCredential(client_id, client_secret)
ctx = ClientContext(SP_SITE_URL).with_credentials(client_credentials)
file_url = FOLDER_URL + current_file_name
response = File.open_binary(ctx, file_url)但我得到错误403 :B‘{“错误”:{“代码”:“-2147024891,System.UnauthorizedAccessException",”message“:{”lang“:”en“,”value“:”访问被拒绝“。( HRESULT: 0x80070005 (E_ACCESSDENIED)的例外)}’}}‘
我知道我需要添加一个层来连接微软并得到一个令牌?但是我找不到在这两个步骤之间进行连接的代码。有什么想法吗?
发布于 2022-07-13 13:50:29
我想你的ClientContext电话有问题。如果您使用的是用户/密码,那么您应该使用您之前创建的client_credentials对象。它应该是这样的:
ctx = ClientContext(SP_SITE_URL).with_user_credentials(client_credentials)还请确保您的用户没有启用MFA,并且用户具有访问SP站点的权限。
https://stackoverflow.com/questions/72967246
复制相似问题