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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
samithc
Frequent Visitor

Error when trying to connect the Data Set using Python Script in Power BI

Hi 

 

When i am trying to use python script to connect the Data set in Power BI. i am getting the below error. Python script was for getting data from Kaggle using Kaggle API. 

 

Details: "An error happened while reading data from the provider: 'Object reference not set to an instance of an object.'"

 

When I retry then the below error is coming. 

 

Details: "ADO.NET: Unable to find the requested .Net Framework Data Provider. It may not be installed."

 

can anyone advise what will be the issue. 

 

Regards, 

Samith 

1 ACCEPTED SOLUTION
samithc
Frequent Visitor

Hi All, 

 

i have found the solution for error. i was trying many things. Atlast I went to the C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config and edited the machine.config. 

in that file MySql.Data.MySqlClient was there 2 times. I have removed the duplicate and now I am able to run the python script. 

Thank you all for the response. 

 

Reagrds, 

 

Samith 

View solution in original post

7 REPLIES 7
samithc
Frequent Visitor

Hi All, 

 

i have found the solution for error. i was trying many things. Atlast I went to the C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config and edited the machine.config. 

in that file MySql.Data.MySqlClient was there 2 times. I have removed the duplicate and now I am able to run the python script. 

Thank you all for the response. 

 

Reagrds, 

 

Samith 

Walter726Herrin
New Member

Hi Samith,

The errors in Power BI might be due to uninitialized objects or missing .NET Framework components. Ensure all objects in your Python script are properly initialized and check for null values. Also, verify that the necessary .NET Framework Data Provider is installed. Updating Power BI and checking dependencies for your Python script and Kaggle API might help. If the issue persists, consider reinstalling the .NET Framework or checking Power BI community forums.

Hi @Walter726Herrin ,  

 

Below python script i have tried in VS CODE and it is working in VS CODE. 

 

import kaggle
import os
import pandas as pd

# Set Kaggle API credentials directory
os.environ['KAGGLE_CONFIG_DIR'] = 'C:/Users/samit/.kaggle'  

# Specify the dataset identifier
dataset = 'piterfm/paris-2024-olympic-summer-games'

# Set the download path
download_path = r'D:\SAMITH\Power BI\Paris 2024 Olympics Dashboard\Source'

# Remove existing files in the folder to prevent duplicates or outdated files
for file in os.listdir(download_path):
    file_path = os.path.join(download_path, file)
    try:
        if os.path.isfile(file_path):
            os.unlink(file_path)  # Delete the file
            print(f"Deleted {file_path}")
    except Exception as e:
        print(f"Error deleting {file_path}: {e}")

# Download the dataset using the Kaggle API and unzip the files
kaggle.api.dataset_download_files(dataset, path=download_path, unzip=True)

# List of CSV files to be imported
csv_files = [
    'athletes.csv',
    'events.csv',
    'medallists.csv',
    'medals.csv',
    'medals_total.csv',
    'schedules.csv',
    'schedules_preliminary.csv',
    'teams.csv',
    'torch_route.csv',
    'venues.csv'
]

# Initialize a dictionary to hold DataFrames
dataframes = {}

# Iterate through each CSV file and load it into a DataFrame
for file in csv_files:
    # Construct the full path to the CSV file
    file_path = os.path.join(download_path, file)
   
    # Load the CSV file into a Pandas DataFrame
    df = pd.read_csv(file_path)
   
    # Add the DataFrame to the dictionary using the file name as the key
    table_name = file.split('.')[0]  # Remove the .csv extension
    dataframes[table_name] = df
 
Also have tried installing .netframework 8. Not sure how to install  .NET Framework Data Provider. 
 
Regards, 
 
Samith 
Greg_Deckler
Super User
Super User

@samithc "connect the data set in Power BI" Can you elaborate on that. A data set in the Service? A local data set when you have Power BI open? A data set within Power BI Desktop as in a Python visual? 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler , 

 

Using the below Python code. I was trying to get the date to Power BI. 

 

''' python

 

import kaggle
import os
import pandas as pd

# Set Kaggle API credentials directory
os.environ['KAGGLE_CONFIG_DIR'] = 'C:/Users/samit/.kaggle'  

# Specify the dataset identifier
dataset = 'piterfm/paris-2024-olympic-summer-games'

# Set the download path
download_path = r'D:\SAMITH\Power BI\Paris 2024 Olympics Dashboard\Source'

# Remove existing files in the folder to prevent duplicates or outdated files
for file in os.listdir(download_path):
    file_path = os.path.join(download_path, file)
    try:
        if os.path.isfile(file_path):
            os.unlink(file_path)  # Delete the file
            print(f"Deleted {file_path}")
    except Exception as e:
        print(f"Error deleting {file_path}: {e}")

# Download the dataset using the Kaggle API and unzip the files
kaggle.api.dataset_download_files(dataset, path=download_path, unzip=True)

# List of CSV files to be imported
csv_files = [
    'athletes.csv',
    'events.csv',
    'medallists.csv',
    'medals.csv',
    'medals_total.csv',
    'schedules.csv',
    'schedules_preliminary.csv',
    'teams.csv',
    'torch_route.csv',
    'venues.csv'
]

# Initialize a dictionary to hold DataFrames
dataframes = {}

# Iterate through each CSV file and load it into a DataFrame
for file in csv_files:
    # Construct the full path to the CSV file
    file_path = os.path.join(download_path, file)
   
    # Load the CSV file into a Pandas DataFrame
    df = pd.read_csv(file_path)
   
    # Add the DataFrame to the dictionary using the file name as the key
    table_name = file.split('.')[0]  # Remove the .csv extension
    dataframes[table_name] = df

'''

 

I am getting the below errors : Each time I retry then error getting changed to each other. I have tried installing .net framework 8. Also tried the My SQL connecter and re-installed power bi from website. 

1) Details: "An error occurred creating the configuration section handler for system.data: Column 'InvariantName' is constrained to be unique. Value 'MySql.Data.MySqlClient' is already present. (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config line 155). This is a configuration issue with the file 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config'."

 

2) Details: "ADO.NET: Unable to find the requested .Net Framework Data Provider. It may not be installed."

 

 

 

 

Screenshot 2024-08-31 141105.jpg

@samithc Your script worked perfectly for me. See attached PBIX below signature. But, I started with a simple enter data query whereas it seems like maybe you started with a MySQL query?

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg, 

 

But i am getting the below error. 

 

 

DataSource.Error: An error occurred creating the configuration section handler for system.data: Column 'InvariantName' is constrained to be unique. Value 'MySql.Data.MySqlClient' is already present. (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config line 155). This is a configuration issue with the file 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config'.
Details:
DataSourceKind=Python
DataSourcePath=Python

 

Regards, 

 

Samith 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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