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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.