Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
drew_darke
Frequent Visitor

Data Loading with Python Scripts throwing Error - 2021

Hey All So I'm pulling data from Statistics Canada with their API. I am using a Python Script to bring it in because there are no restraints. I will post my code block, and then the error I am getting. Thanks ahead of time to anybody that can help!

 

*MY SCRIPT*

import requests, json, zipfile, zlib
from io import BytesIO
import pandas as pd


def df_from_statscan(tableid):
url = f"https://www150.statcan.gc.ca/t1/wds/rest/getFullTableDownloadCSV/{tableid}/en"
r = requests.get(url)
downloadurl = json.loads(r.content)["object"]
r = requests.get(downloadurl)
if r.status_code == 200:
csvzipbytes = r.content
csvzip = zipfile.ZipFile(BytesIO(csvzipbytes))
csvcontent = csvzip.read(csvzip.namelist()[0])
df = pd.read_csv(BytesIO(csvcontent))
return df


df_from_statscan("11100106")

 

*****************************************

 

UNABLE TO CONNECT:

We encountered an error while trying to connect.

Details: "ADO.NET: Python script error.
<pi>Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib
File "C:\PROGRAMDATA\ANACONDA3\lib\site-packages\matplotlib\__init__.py", line 205, in <module>
_check_versions()
File "C:\PROGRAMDATA\ANACONDA3\lib\site-packages\matplotlib\__init__.py", line 190, in _check_versions
from . import ft2font
ImportError: DLL load failed: The file cannot be accessed by the system.
</pi>"

******************************************************

 

I program in Python and I am familiar with Data Science using Python but I am not recognizing these exceptions being thrown. Thanks to anybody who can help!

2 REPLIES 2
Anonymous
Not applicable

Hi @drew_darke 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your problem.

 

Best Regards,

Rico Zhou

Anonymous
Not applicable

Hi @drew_darke 

Which version of python did you use to connect to your data source? You install try Python 36 and try again.

And please check whether the environment of your python has been configured correctly.

For reference: Run Python scripts in Power BI Desktop

Try to start PBIDesktop from within an activated conda environment and have the Python home directory configured.

 

From the Anaconda Prompt run:

(base) C:> "Program Files\Microsoft Power BI Desktop\bin\PBIDesktop.exe"

 

If you download your desktop from app store , windows 10 Apps are stored in C:\Program Files\WindowsApps.

C:\Program Files\WindowsApps\Microsoft.MicrosoftPowerBIDesktop_2.75.5653.0_x64__8wekyb3d8bbwe\bin\PBIDesktop.exe

However, the WindowsApps folder is both hidden and protected, but with admin rights you can take over ownership like described e.g. in this article: https://www.maketecheasier.com/access-windowsapps-folder-windows-10/.

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.