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

标签 python api sharepoint office365api sharepoint-api

我正在尝试使用以下代码连接到 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/

相关文章:

c# - 如何以编程方式打开 IE8 兼容性 View

vba - 将文件保存到 OneDrive/Sharepoint

python - 如何通过查找内部 div 的元素来单击外部 div

ruby-on-rails - 在 View 中显示来自 api 的 JSON 响应

api - 使用 Chrome TTS 的 SSML

Sharepoint 周末总是宕机?

python - 从 Sublime Text 2 中交互式运行 Python

python 创建签名 X509

python - Django 连接到 Redis

rest - 微软团队 : REST APIs