Python Forum
Command error - cursor.executemany(comandoSQL,valoresInserir)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Command error - cursor.executemany(comandoSQL,valoresInserir)
#1
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()
Yoriz write Nov-18-2022, 01:44 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Did you try to add some debug print calls to see what valoresInserir looks like when error happens?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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()
buran write Nov-18-2022, 02:26 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error: invalid command 'egg_info' TimTu 0 963 Jul-27-2023, 07:30 AM
Last Post: TimTu
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,398 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Cursor Variable inside Another Cursor . CX_ORacle paulo79 1 1,530 Apr-09-2022, 10:24 AM
Last Post: ibreeden
  ERROR: Command errored out with exit status 1 calesii 3 7,192 Oct-23-2020, 05:39 PM
Last Post: snippsat
  MERGE SQL in oracle executemany kaladin 0 3,113 Oct-12-2020, 11:48 AM
Last Post: kaladin
  Error when running mktorrent subprocess command pythonnewbie138 4 3,878 Sep-16-2020, 01:55 AM
Last Post: pythonnewbie138
  "pip install -e ." returns : ERROR: Command errored out with exit status 1 mostafaPython 3 5,523 Jun-09-2020, 09:28 AM
Last Post: snippsat
  Using executemany to import the data Sandy7771989 1 2,699 Jun-11-2019, 07:45 AM
Last Post: Sandy7771989
  MySQL executemany - Failed executing the operation; Could not process parameters josh_marchant 1 8,032 May-16-2019, 04:22 PM
Last Post: woooee
  Read CSV file into MySQL and use executemany instead of execute bluethundr 1 4,209 May-04-2019, 07:35 AM
Last Post: MvGulik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020