AADSTS90023: Invalid STS request (Python and Office365 SharePoint)

Andre Lourenco 0 Reputation points
2024-02-12T14:18:50.8833333+00:00

I am trying to access files on my organisation's SharePoint through Python. I have installed office365-rest-python-client (v.2.5.5) and I am using Python 3.11.5 and Ubuntu 22.04.1 LTS. I have tried to run this code, with multiple accounts, but I always get the same error (ValueError: An error occurred while retrieving token from XML response: AADSTS90023: Invalid STS request). This error is raised in the line ctx.execute_query(). Note that for example my password does not contain any special characters. The code that I am running can be found below. I wonder if there is any sort of configuration that I need to do first. Thank you in advance.

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext

url = "https://{netorg_number}.sharepoint.com/sites/{company_name}"
user = "******@domain.com"
password = "password"

ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(user, password):
    ctx = ClientContext(url, ctx_auth)
    web = ctx.web
    ctx.load(web)
    ctx.execute_query()
    print("Authentication successful")
Microsoft 365 and Office | SharePoint | Development
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2024-02-13T07:18:00.1066667+00:00

    Hi @Andre Lourenco, Since our forum focus on c#, I am not familar with python. After doing some research, I found a similar issue with yours. Please make a reference, thanks for your reference https://github.com/vgrem/Office365-REST-Python-Client/issues/320

    ---If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.