Forum Discussion
Power-bi: Python Requests package doesn't work on powerbi Service, throws module not found error.
Hi,
We need to make API call using python script in powerbi, for which we needed to add python import requests package which works well in powerbi desktop but on powerbi service it gives "ModuleNotFounError:No module named 'requests"
Can you please help why python requests package in not supported on service and what is alternative to make it work?
Looking forward to hear from you!!
4 Replies
- AnonymousNot applicable
Hi Abha ,
According to the official documentation, the requests package is not supported in the Power BI service. This is because the service doesn't support Python packages that provide client-server queries over the World-Wide Web for security and privacy reasons.
As an alternative, you can try to use the urllib package, which is a built-in Python module for handling URLs. You can use it to make HTTP requests and parse the response data. Here is an example of how to use it in Power BI Desktop:
```python
import urllib.request
import pandas as pd# Define the API endpoint
url = "https://api.exchangeratesapi.io/latest"# Make a GET request and read the response
response = urllib.request.urlopen(url)
data = response.read()# Convert the response data to a pandas DataFrame
df = pd.read_json(data)# Extract the rates as a list of tuples
rates = list(df["rates"].items())# Create a new DataFrame with the rates
rates_df = pd.DataFrame(rates, columns=["Currency", "Rate"])
```Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AbhaFrequent Visitor
Thanks for responding.
the urllib also gives error on service: urllib.error.URLError
- AnonymousNot applicable
Hi Abha ,
Try it.
import urllib.request url = "https://example.com/api/endpoint" response = urllib.request.urlopen(url) data = response.read().decode("utf-8")Replace the url variable with the API endpoint you want to call.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.