0
I’m making a program that reads the output of Arduino and sends to a SQLITE3 database.
You’re making this mistake:
cursor.execute("INSERT INTO reciclagem_data (personID, nome) VALUES (%s,%s)", (pieces[0], pieces[1]))
OperationalError: near "%": syntax error
personID is the UID of an RFID card and the name is simply the name.
I researched and found that the best type of date for UID would be to sweep. I think the mistake has to do with this subject.
What should I do to solve this problem?
Would not be
VALUES (?, ?)
?– bfavaretto
@bfavaretto, can you explain why? I’m struggling. I know that %s is for string and %d is for integer.
– Tiago Gonçalves
@bfavaretto, you’re making this mistake with your suggestion. Programmingerror: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly Recommended that you Instead just switch your application to Unicode strings.
– Tiago Gonçalves
This error seems to be caused by some data, must be one of the names, probably something accentuated. About why use as I said, I saw in documentation.
– bfavaretto
@bfavaretto, you’re making this mistake with your suggestion. Programmingerror: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly Recommended that you Instead just switch your application to Unicode strings
– Tiago Gonçalves
So this is what seems to be caused by a question of encoding/strings with accents. I leave it to someone else to say, I’m not an expert in python or sqlite.
– bfavaretto
The name he was using contained a cedilla c, ç. Just changed to c.
– Tiago Gonçalves