0
Someone can help me !
I am reading a csv file and then I do an INSERT in Mysql database, but I get the following error
Keyerror: 'id'
I have checked the CSV file several times, the file has all the columns and exactly the same name..
import csv
import pymysql
# importa o arquivo de acesso ao banco
from config import config
# faz a conexão com o banco de dados
cnx = pymysql.connect(**config, charset='utf8')
cursor = cnx.cursor()
# ler o arquivo csv
input_file = csv.DictReader(open("teste.csv", encoding='utf-8'))
# importa o arquivo csv no banco de dados
for row in input_file:
cursor.execute("INSERT INTO teste.tabela (id,nome) \
VALUES (%s,%s)",(row['id'],row['nome']))
print("Importando Linhas")
cnx.commit()
Could you add in the question some lines from the csv file?
– Camilo Santos