[Python] Failure to authenticate a SharePoint connection with AuthenticationContext

Discussão em 'Python' iniciado por Stack, Março 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following python code in my Matillion PythonScript component:

    from office365.sharepoint.client_context import ClientContext
    from office365.runtime.auth.authentication_context import AuthenticationContext
    authority_url = “https://login.microsoftonline.us/<tenant_id>”

    site_url = “https://mysite.sharepoint.us/sites/myfolder”
    auth_ctx = AuthenticationContext(authority_url)

    if auth_ctx.acquire_token_for_app(client_id, client_secret):
    ctx = ClientContext(site_url, auth_ctx)
    web = ctx.web
    ctx.load(web)
    ctx.execute_query()

    print("Web Title:", web.properties["Title"])
    else:
    raise ValueError(“Failed to acquire token for the given client credentials.”)



    It errors out at ctx.execute_query() with the following error message

    ValueError: {“error”:“invalid_request”,“error_description”:"AADSTS900023: Specified tenant identifier ‘none’ is neither a valid DNS name, nor a valid external domain.

    Is there a way to trouble shoot the cause of this error, since the error message is not very informative?

    Continue reading...

Compartilhe esta Página