Skip to content

ValueError: An error occurred while retrieving auth cookies from sharepoint #1012

@GrumeiA

Description

@GrumeiA

Hello

I am trying to use REST API to retrieve some files from sharepoint, and since 8th of April 2026 I receive this message:

ValueError: An error occurred while retrieving auth cookies from https://company.sharepoint.com/_forms/default.aspx?wa=wsignin1.0

The context creation works fine:

self.username = username
self.password = password
user_credentials = UserCredential(username, password)
self.context = ClientContext(self.sharepoint_url).with_credentials(user_credentials)

The context setup works fine:

# decorate relative url methods
  self.context.web.get_folder_by_server_relative_url = mandatory_path_dec(
      self.context.web.get_folder_by_server_relative_url,
      self.mandatory_rel_path
  )
  self.context.web.get_file_by_server_relative_url = mandatory_path_dec(
      self.context.web.get_file_by_server_relative_url,
      self.mandatory_rel_path
  )

I I try to execute a query, I receive an error:
result = self.context.search.post_query(query_text=f"FileName:'{file_name}'").execute_query()

Error:

An error occurred while retrieving auth cookies from https://company.sharepoint.com/_forms/default.aspx?wa=wsignin1.0
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.1\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\client_result.py", line 54, in execute_query
    self._context.execute_query()
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\client_runtime_context.py", line 173, in execute_query
    self.pending_request().execute_query(qry)
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\client_request.py", line 37, in execute_query
    response = self.execute_request_direct(request)
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\client_request.py", line 46, in execute_request_direct
    self.beforeExecute.notify(request)
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\types\event_handler.py", line 41, in notify
    listener(*args, **kwargs)
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\sharepoint\client_context.py", line 284, in _authenticate_request
    self.authentication_context.authenticate_request(request)
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\auth\authentication_context.py", line 249, in authenticate_request
    self._authenticate(request)
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\auth\authentication_context.py", line 206, in _authenticate
    provider.authenticate_request(request)
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py", line 85, in authenticate_request
    self.ensure_authentication_cookie()
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py", line 97, in ensure_authentication_cookie
    self._cached_auth_cookies = self.get_authentication_cookie()
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py", line 112, in get_authentication_cookie
    return self._get_authentication_cookie(token, user_realm.IsFederated)
  File "D:\scripts\python_sharepoint_api\venv\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py", line 312, in _get_authentication_cookie
    raise ValueError(self.error)
ValueError: An error occurred while retrieving auth cookies from https://company.sharepoint.com/_forms/default.aspx?wa=wsignin1.0

Nothing has changed in the code from my side in the last year, so do you know if something has changed on the OFFICE side ?

I am unsing REST API Office365-REST-Python-Client 2.5.13, but the behaviour is the same with the latest version (2.6.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions