[Python] How to connect to Power BI XMLA Endpoint using InteractiveBrowserCredential in python?

Discussão em 'Python' iniciado por Stack, Maio 8, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying a approach to use the token generated using InteractiveBrowserCredential to connect to Power BI XMLA Endpoint. I was able to connect to the model using pyadomd locally but the same won't work with the Power BI Service models

    import pandas as pd
    from azure.identity import InteractiveBrowserCredential
    from sys import path
    path.append(r'C:\Program Files\Microsoft.NET\ADOMD.NET\150')
    from pyadomd import Pyadomd
    import requests

    # Azure AD credentials


    # Authenticate and get access token
    def get_access_token():
    credentials = InteractiveBrowserCredential()
    scopes = "https://analysis.windows.net/powerbi/api/.default" # Scope for Power BI XMLA
    token = credentials.get_token(scopes)
    return token.token

    # Get the access token
    access_token = get_access_token()

    # Connection string with access token
    conn_str = f"Data Source=powerbi://api.powerbi.com/v1.0/myorg/MY-%20TM;Initial Catalog=My Dataset;User ID=;Password={access_token};"

    # Enter DAX or MDX query
    dax_query = """EVALUATE INFO.VARIATIONS()"""

    # Output results as pandas dataframe
    with Pyadomd(conn_str) as conn:
    with conn.cursor().execute(dax_query) as cur:
    df = pd.DataFrame(
    cur.fetchall(),
    columns=[i.name for i in cur.description]
    )
    print(df)type here

    Continue reading...

Compartilhe esta Página