Office365-rest-python-client: "An error occurred while retrieving auth cookies" request_form_digest()

Created on 24 Jul 2018  ·  8Comments  ·  Source: vgrem/Office365-REST-Python-Client

I had some working code to upload a file to SharePoint in Office 365 but sometimes it fails. Here is the simplified code:

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.runtime.utilities.request_options import RequestOptions
from os.path import basename

ctx_auth = AuthenticationContext(url=base_url)

if not ctx_auth.acquire_token_for_user(username=user_name, password=pwd):
print(ctx_auth.get_last_error())
exit()

file_name = basename(file_path)
files_url ="{0}/_api/web/GetFolderByServerRelativeUrl('{1}')/Files/add(url='{2}', overwrite=true)"
full_url = files_url.format(base_url, folder_url, file_name)

options = RequestOptions(base_url)
context = ClientContext(base_url, ctx_auth)
context.request_form_digest()

Here is the error I get:

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

Any idea why this sometimes works and other times does not? I'm using the correct user name and password.

question

Most helpful comment

I ended up constructing a script to upload a file to SharePoint based on MicroSoft Graph. https://github.com/bobbydurrett/copyfiletosharepoint

All 8 comments

This just started happening to me on Monday. I am still looking for a solution as well.

Yes I also got the same error, started on Monday. Hoping this can be fixed soon. The code is failing at
ctx.excecute_query()

ctx_auth = AuthenticationContext(url)

if 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'])

else:
    print ctx_auth.get_last_error()

getting the following error:

return 'FedAuth=' + self.FedAuth + '; rtFa=' + self.rtFa
TypeError: cannot concatenate 'str' and 'NoneType' objects

Getting similar error. The errors is either of the below. Looking for some solutions but nothing worked yet, so appreciate a fix.

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 token: AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password

Please note that same username and password work when the site is accessed through Browser.

Thanks.

I ended up constructing a script to upload a file to SharePoint based on MicroSoft Graph. https://github.com/bobbydurrett/copyfiletosharepoint

Thanks @bobbydurrett This is really useful!

I have the same error with an internal account (AD Azure for O365) but with an external account, the authentication process works fine! @majduddin @zachnamyat @EGCPHD did you found a solution?

Propose to close this one since the similar issue has been confirmed as resolved in 2.1.10 version and so far no one has encountered it any longer

Was this page helpful?
0 / 5 - 0 ratings