Forum Discussion

Kobold67's avatar
Kobold67
New Member
6 years ago

Passing parameters from Power BI to Python script for the first step in a data source

The first step as data source is a Python script which collects the data from an Azure DevOps Server on-premise. In order to use the OData feed of the server I have to pass an authentication token. To make later change easier, I would like to pass the URL of the server as well as the authentication token from Power BI into the Python script.

 

Here comes a short snippet from the advanced editor:

 

let
    Source = Python.Execute("import pandas as pd#(lf)import numpy as np#(lf)import requests#(lf)import json#(lf)import os#(lf)import sys#(lf)import pathlib#(lf)import ppr

 

 

The related Python code looks like:

 

import pandas as pd
import numpy as np
import requests
import json
import os
import sys
import pathlib
import pprint
import configparser
from requests.auth import HTTPBasicAuth
from decimal import Decimal

# Read parameter from environment (Power BI) -> does not work at the moment as first step (hardcoded for now)
#ados_url = "&Text.From(ADOSServer)&"
#personal_access_token = "&Text.From(AccessToken)&"
ados_url = "http://xxx/_odata/v2.0/"
personal_access_token = "yyyyyyyyyyyyy"

 

 

There a a couple of examples available, but in these examples the parameter are used not as first step inside the data source. As soon as I try to use the parameter already within the Source= statement, the parameter are never expanded.

 

I tried up to now the following examples:

 

ados_url = """ & ADOSServer """
ados_url = '"&Text.From(ADOSServer)&"'
ados_url = "&Text.From(ADOSServer)&"

 

 

None of them worked. I got always the string after the assignment.

 

Any ideas?

 

4 Replies