Forum Discussion
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
- amitchandakSuper User
Kobold67 , Refer if this can help
https://docs.microsoft.com/en-us/power-bi/desktop-python-in-query-editor
- Kobold67New Member
The article does not help me. The solution is working, however the only problem at the moment is, that I like to move out the server URL and access token from the python script. Otherwise I have to re-enter this after expiration (token last for around a year) in all data sources provided from the script.
- ZaidNew Member
Hi,
Please help me with this, I am facing this same issue.
Thanks
- koushikpFrequent Visitor
Any other solution here? I am on the same boat.