Not all Arguments converted During bytes formatting Insert Python

Asked

Viewed 258 times

-4

I was trying to add python integer values to a mysql database with the following code:

import MySQLdb
valor1 = input("Digite o primeiro valor: ")
valor2 = input("Digite o segundo valor: ")
conexaoMySQL = MySQLdb.connect(host="localhost",user="User",db="Database",passwd="password")
cursor = conexaoMySQL.cursor()
conexaoMySQL.select_db('password')
cursor.execute('INSERT INTO Dados (Campo1,Campo2) VALUES(?, ?)', 
(valor1,valor2))
conexaoMySQL.commit()
conexaoMySQL.close()

But I’m getting this mistake:

line 204, in execute query = query % args

Typeerror: not all Arguments converted During bytes formatting

During Handling of the above Exception, Another Exception occurred:

Traceback (Most recent call last): File "/home/hymb/Pycharmprojects/Pythondevid01/Appclientpy/pro.py", line 8, in cursor.execute('INSERT INTO Data(Field1,Field2) VALUES(?, ?)',(value1,value2)) File "/home/hymb/Virtualdevlopmentpython/lib/python3.6/site-Packages/Mysqldb/Cursors.py", line 206, in execute raise Programmingerror(str(m)) Mysqldb. _exceptions.Programmingerror: not all Arguments converted During bytes formatting

In Mysql I have a database and a table with two fields that receive integers

  • You own 5 ? in consultation and passes 6 values...

  • Now that you’ve seen it, thank you

  • If you change this in the question will not stop giving this error? Your question will no longer make sense...

  • It’s not working yet, I already changed the values in my original code

  • And exactly the same error occurs? Then it will be better to elaborate a [mcve] for the question

  • Okay, I’ll try to do

Show 1 more comment

1 answer

2


To run the code you need to convert the values to another Mysql interpretable value. This requires changing the question marks(?) by %s

Browser other questions tagged

You are not signed in. Login or sign up in order to post.