Friday, 3 December 2021

Error opening connection to Power BI XMLA endpoint with Python

I have the following python code which works fine on first execution.

import adodbapi

# Connection string
conn = adodbapi.connect("""
Provider=MSOLAP.8;
Identity Provider=https://login.microsoftonline.com/common, https://analysis.windows.net/powerbi/api, 929d0ec0-7a41-4b1e-bc7c-b754a28bddcc;
Data Source=pbiazure://api.powerbi.com;
Initial Catalog=[dataset_id];
User Id=[username];
Password=[pass];
""")

# Example query
print('The tables in your database are:')
for name in conn.get_table_names():
    print(name)
conn.close()

However when it try to run it for the 2nd time it fails after a long wait with the following error message.

OperationalError: (com_error(-2147352567, 'Exception occurred.', (0, 'Provider', None, None, 1240640, -894947614), None), 'Error opening connection to "\nProvider=MSOLAP.8;\nIdentity Provider=https://login.microsoftonline.com/common, https://analysis.windows.net/powerbi/api, 929d0ec0-7a41-4b1e-bc7c-b754a28bddcc;\nData Source=pbiazure://api.powerbi.com;\nInitial Catalog=[dataset_id];\nUser Id=[username];\nPassword=[pass];\n"')

I noticed that I am able to run it consecutively multiple times if I perform a kernel restart in between.

What do I need to change in the code to be able to run this script multiple times without errors?



from Error opening connection to Power BI XMLA endpoint with Python

No comments:

Post a Comment