Forum Discussion
Error when trying to connect the Data Set using Python Script in Power BI
- 2 years ago
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
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?
- samithc2 years agoFrequent Visitor
Hi Greg_Deckler ,
Using the below Python code. I was trying to get the date to Power BI.
''' python
import kaggleimport osimport pandas as pd# Set Kaggle API credentials directoryos.environ['KAGGLE_CONFIG_DIR'] = 'C:/Users/samit/.kaggle'# Specify the dataset identifierdataset = 'piterfm/paris-2024-olympic-summer-games'# Set the download pathdownload_path = r'D:\SAMITH\Power BI\Paris 2024 Olympics Dashboard\Source'# Remove existing files in the folder to prevent duplicates or outdated filesfor 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 fileprint(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 fileskaggle.api.dataset_download_files(dataset, path=download_path, unzip=True)# List of CSV files to be importedcsv_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 DataFramesdataframes = {}# Iterate through each CSV file and load it into a DataFramefor file in csv_files:# Construct the full path to the CSV filefile_path = os.path.join(download_path, file)# Load the CSV file into a Pandas DataFramedf = pd.read_csv(file_path)# Add the DataFrame to the dictionary using the file name as the keytable_name = file.split('.')[0] # Remove the .csv extensiondataframes[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."
- Greg_Deckler2 years ago
Community Champion
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?
- samithc2 years agoFrequent Visitor
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=PythonRegards,
Samith