AADSTS70002,AADSTS50053使用Python连接到Office 365 Sharepoint时出错

2024-06-28 06:19:08 发布

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

我有一个Python程序,它有时连接到office365上的SharePoint,有时会失败。我目前看到以下症状。在

下面是我的print语句无法显示输入和输出的部分代码:

    sts_url = 'https://' + options['sts']['host'] + options['sts']['path']
    print(sts_url)
    print(request_body)
    response = requests.post(sts_url, data=request_body,
                             headers={'Content-Type': 'application/x-www-form-urlencoded'})
    print(response.content)

以下是标准输出,除了我的用户id、密码和SharePoint URL被替换为安全假值之外:

^{pr2}$

以下是标准错误输出:

An error occurred while retrieving token: AADSTS70002: Error validating credentials. AADSTS50053: You've tried to sign in too many times with an incorrect user ID or password.
An error occurred while retrieving auth cookies
Traceback (most recent call last):
  File "testsimplified.py", line 24, in <module>
    context.request_form_digest()
  File "C:\todoitems\pysharepointerrers\office365\sharepoint\client_context.py", line 33, in request_form_digest
    self.authenticate_request(request)
  File "C:\todoitems\pysharepointerrers\office365\runtime\client_runtime_context.py", line 16, in authenticate_request
    self.__auth_context.authenticate_request(request)
  File "C:\todoitems\pysharepointerrers\office365\runtime\auth\authentication_context.py", line 27, in authenticate_request
    request_options.set_header('Cookie', self.provider.get_authentication_cookie())
  File "C:\todoitems\pysharepointerrers\office365\runtime\auth\saml_token_provider.py", line 69, in get_authentication_cookie
    return 'FedAuth=' + self.FedAuth + '; rtFa=' + self.rtFa
TypeError: must be str, not NoneType

这一切都是基于我之前的一篇帖子中的一些代码。以下是我将文件上载到Office 365上的SharePoint的代码。在

https://github.com/bobbydurrett/miscpython/blob/master/uploadfile.py

有时候效果很好。其他时候我会出错。我一开始没有收到AADSTS50053错误。一开始我得到错误的密码错误。但每次运行它时,它都有正确的用户id和密码。在

有什么想法吗?我也在GitHub上提交了一个关于这个的问题:

https://github.com/vgrem/Office365-REST-Python-Client/issues/80

对于这个SO问题,我找到了发生错误的请求,并发布了before和after值。在

提前谢谢你的帮助。在

鲍比


Tags: inpyselfauthrequest错误contextline