使用公司帐户读取SharePoint上的excel文件时,条件访问策略错误阻止了访问

2024-06-16 13:00:09 发布

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

我试图使用python3读取位于sharepoint上的excel文件,该文件包含公司的帐户。 下面是我从Dan's复制/修改的代码惊人的答案in this post

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.file import File 

url = 'https://company.sharepointsite.com/sites/documentsite'
username = 'username'
password = 'password'
relative_url = '/sites/documentsite/Documents/filename.xlsx'
ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(username, password):
  ctx = ClientContext(url, ctx_auth)
  web = ctx.web
  ctx.load(web)
  ctx.execute_query()
  print "Web title: {0}".format(web.properties['Title'])

else:
  print ctx_auth.get_last_error()

以下是我得到的错误: enter image description here

这是否意味着该公司正在阻止代币?我需要和公司的管理员谈谈做点什么

任何帮助都将不胜感激!!!谢谢


Tags: 文件fromimportauthweburlcontextusername
2条回答

英南

在这种情况下,我要做的是创建一个具有代码运行所需权限的用户,或者为用户创建一个组以使用此代码。如果您对他们进行分组,您将需要查看他们需要使用多少,比如说您的组的“站点权限”或者“集合级别权限”

您必须在代码中正确设置权限,才能执行希望在此处完成的功能

这是集合权限、网站权限、Web部件权限、列表权限,然后是SharePoint中的文件夹权限和Windows权限

相关问题 更多 >