Wie verbindet ich mithilfe von InteractiveBrowsercredential in Python einen Verbindung zum Power BI XMLA -Endpunkt?Python

Python-Programme
Anonymous
 Wie verbindet ich mithilfe von InteractiveBrowsercredential in Python einen Verbindung zum Power BI XMLA -Endpunkt?

Post by Anonymous »

Ich versuche einen Ansatz zur Verwendung des mit interActiveBrowsercredential generierten Tokens, um eine Verbindung zum Power BI XMLA -Endpunkt herzustellen. Ich konnte mich mit Pyadomd lokal mit dem Modell verbinden, aber das Gleiche funktioniert nicht mit den Power BI -Service -Modellen < /p>

Code: Select all

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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post