0
I am writing a Python code that inserts the data of a CSV into a Mysql table.
if os.path.isfile('\\offline.csv'):
try:
csv = csv.reader(open('\\offline.csv', encoding='utf-8'))
for row in csv:
conn = connect()
cursor = conn.cursor()
query = "INSERT INTO maquina(processador, mb_fabricante, mb_modelo, mb_num_serie, sis_hostname, sis_versao_sistema, sis_data_instalacao, rede_ipv4, rede_macaddress, rede_srv_dns, memoria_ram, total_hd, nome_tecnico)VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);"
cursor.execute(query, row)
conn.commit()
print('sucesso csv')
cursor.close()
conn.close()
except Exception as erro:
print('erro csv', erro)
The problem that occurs is the following: the header data that are the names of the database columns are inserted as records, but the following data, which would be inserted to return the error: csv not enough arguments for format string
.
The CSV is this:
I would like to ignore the header data and just insert the next row. I have tried to manually delete the header but the error persists.
It worked perfectly, the error was related to blank line. I lost almost two days cracking my head. Very grateful.
– Algeu Junior
It happens a lot with everyone :)
– GigaFrota