Sharepoint API Python Office365 Rest API库的身份验证错误

2024-09-28 16:49:25 发布

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

我正在尝试使用以下代码连接到Sharepoint。它以前工作,但突然停止工作,现在显示以下错误:

 File "C:\Users\Documents\Anaconda2\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 67, in get_authentication_cookie
return 'FedAuth=' + self.FedAuth + '; rtFa=' + self.rtFa

TypeError:无法连接“str”和“NoneType”对象

^{pr2}$

如果ctx_用户的身份验证获取令牌(用户名、密码):

print("Authentication with SharePoint was successful: {0}".format(
        ctx_auth.acquire_token_for_user(username, password)))

ctx = ClientContext(url, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
print "SharePoint Site: {0}".format(web.properties['Title'])

其他: 打印ctx_auth.get_last_错误()

它在这条线上失败了:

ctx.execute_query()

Tags: 代码selftokenauthwebformatexecuteget
1条回答
网友
1楼 · 发布于 2024-09-28 16:49:25

我一直在使用sharepy库作为连接到Sharepoint的替代解决方案。
使用pip install sharepy安装模块。在

import sharepy
from sharepy import connect
from sharepy import SharePointSession

server='youraccount.sharepoint.com'
user='username@domain.com'
password='password'

s = sharepy.connect(server,user,password) 

# Example request to Sharepoint
headers = {'accept': 'application/atom+json'} #json can be changed to xml
r = s.get("https://youraccount.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('path_to_your_folder/')/Files", headers=headers)

认证成功后,应打印出以下内容:

Requesting security token...Requesting access cookie... Authentication successful

相关问题 更多 >