Python inserts UTF8 string into SQLite
I know there are similar questions, but the answers are different and confusing.
I have this line:
titulo = "Así Habló Zaratustra (Cómic)"
When I try to insert it into a SQLite database, I get the error:
sqlite3.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.
I've tried a couple of things with no success. Please, help.
+3
alejoss
source
to share
1 answer
Do as it tells you and use values instead unicode
:
titulo_unicode = titulo.decode('utf8')
The library sqlite3
will take care of the correct encoding on insert, decoding on select.
+5
Martijn pieters
source
to share