我正在尝试使用以下代码连接到 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
类型错误:无法连接“str”和“NoneType”对象
ctx_auth = AuthenticationContext(url)
如果 ctx_auth.acquire_token_for_user(用户名,密码):
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_error()
在这一行失败:
ctx.execute_query()
最佳答案
我一直在使用 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
关于python - Sharepoint API Python Office365 Rest API 库的身份验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51500420/