【问题标题】:Authentication error with Sharepoint API Python Office365 Rest API librarySharepoint API Python Office365 Rest API库的身份验证错误
【发布时间】:2019-01-15 18:38:40
【问题描述】:

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

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()

【问题讨论】:

    标签: python api sharepoint office365api sharepoint-api


    【解决方案1】:

    我一直使用 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)
    

    验证成功后应该会打印出以下内容:

    正在请求安全令牌...正在请求访问 cookie...身份验证成功

    【讨论】:

    • 我不断收到此错误:“'NoneType' 对象没有属性 'group'”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-22
    • 2014-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    相关资源
    最近更新 更多