4

I know there are similar questions, but the answers are distinct and kind of confusing.

I have this string:

titulo = "Así Habló Zaratustra (Cómic)"

When I try to insert it to the 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 without success. Please help.

1 Answer 1

9

Do what it tells you to do and use unicode values instead:

titulo_unicode = titulo.decode('utf8')

The sqlite3 library will take care of encoding this correctly when inserting, decoding again when selecting.

Sign up to request clarification or add additional context in comments.

2 Comments

Hopefully this is no longer a problem unless you're using ancient Python 2.x.
@MarkRansom: well, back in September 2014 Python 2.7 was the norm; Python 3.5 was only just out but most Python shops stuck to 2.x still. The tide was just about to turn by this point, however. I've added the python-2.x tag to the question to make it clear what context this should be read in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.