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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
v-rzhou-msft
Community Support
Community Support

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

v-rzhou-msft
Community Support
Community Support

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.