0

I'm trying to insert some records in the mysql database, using the petl module but it returns the error: mysql.connector.errors.

ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' at line 1

# nova script dec carga
import mysql.connector
import datetime as dt
import petl as etl

#connect ao database 
mydb = mysql.connector.connect(user='root',password='mysql',host='0.0.0.0',database='mydesenv')
cur = mydb.cursor()
# verifica se o arquivo existe
try:
    tbl = (etl.fromcsv('/Users/eduardoaandrad/Dropbox/Desenv/python/3_analise/infopreco.csv', encoding = "ISO-8859-1",delimiter=';')
              .convert('CNPJ'         ,  int   )
              .convert('NOME'         , 'upper')
              .convert('ENDERECO'     , 'upper')
              .convert('COMPLEMENTO'  , 'upper')
              .convert('BAIRRO'       , 'upper')
              .convert('MUNICOPIO'    , 'upper')
              .convert('UF'           , 'upper')
              .convert('PRODUTO'      , 'upper')
              .addfield('DATA_CARGA'  , dt.date.today() )
          ) 
    table = etl.fromdb(mydb, 'insert into mydesenv.t_stg_valores(CNPJ, NOME, ENDERECO, COMPLEMENTO, BAIRRO, MUNICIPIO, UF, PRODUTO, VALOR_VENDA, DATA_CADASTRO) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', tbl)
    print(table)
except IOError:
    print('Arquivo não encontrado') 
Barmar
  • 741,623
  • 53
  • 500
  • 612

0 Answers0