Python Forum

Full Version: Command error - cursor.executemany(comandoSQL,valoresInserir)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good morning,
I'm developing a program that records data coming from JSON in the MySQL database, but it's generating the following error.
Error:
Traceback (most recent call last): File "c:\Projetos\api\getCliente\getClienteMySQL.py", line 58, in <module> cursor.executemany(comandoSQL,valoresInserir) File "C:\Python310\lib\site-packages\mysql\connector\cursor_cext.py", line 375, in executemany self.execute(operation, params) File "C:\Python310\lib\site-packages\mysql\connector\cursor_cext.py", line 271, in execute raise ProgrammingError( mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement [Done] exited with code=1 in 2.222 seconds
Code snippet.
while cliente['hasNext'] == True:
    valoresInserir = []
    nPage = nPage + 1
    request = requests.get('http://srv009:8080/api/cdp/v1/getCliente?page=' + str(nPage) + '&pageSize=100', auth=('userapi', '1q2w!Q@WAPIpw'))
    cliente = request.json()
    for clientes in cliente['items']:
        valoresInserir.append((clientes['clienteId'], clientes['nomeAbrev'], clientes['nome']))
    comandoSQL = f'INSERT INTO cliente (clienteID, nomeAbrev, nome) VALUES (?, UPPER(?), UPPER(?))'
    cursor.executemany(comandoSQL,valoresInserir)
    conexao.commit()
Did you try to add some debug print calls to see what valoresInserir looks like when error happens?
Hello,
Problem solved.

while cliente['hasNext'] == True:
    valoresInserir = []
    nPage = nPage + 1
    request = requests.get('http://srv009:8080/api/cdp/v1/getCliente?page=' + str(nPage) + '&pageSize=100', auth=('userapi', 'xxxx'))
    cliente = request.json()
    comandoSQL = 'INSERT INTO cliente (clienteID, nomeAbrev, nome) VALUES (%s, UPPER(%s), UPPER(%s))'
    for clientes in cliente['items']:
        valoresInserir.append((clientes['clienteId'], clientes['nomeAbrev'], clientes['nome']))
    cursor.executemany(comandoSQL,valoresInserir)
    conexao.commit()