Forum Discussion
Power-bi: Python Requests package doesn't work on powerbi Service, throws module not found error.
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.
Thanks for responding.
the urllib also gives error on service: urllib.error.URLError
- Anonymous3 years agoNot 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.
- WoodDad791 year agoFrequent Visitor
I'm facing this same problem and I tried using urllib instead of requests but no luck. Still blocked for python visuals in PBI service. Has anybody found a workaround?