As soon as you have a string of bytes s , instead of directly using it as a unicode obj, I will explicitly convert it to the right codec, for example:
u = s.decode('latin-1')
and use u instead of s in the code that follows this point (presumably the part that is written in sqlite). Suppose latin-1 is the encoding that was used for the original byte string - we cannot guess, so try to find out; -).
As a rule, I suggest: do not process any text in the form of encoded byte strings in your applications - decode them into unicode objects immediately after input and, if necessary, encode them back to byte strings immediately before output.
Alex martelli
source share