sqlite utf8 encoding error

Fredrik Lundh fredrik at pythonware.com
Thu Nov 17 07:04:25 EST 2005


Greg Miller wrote:

> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 13-18:
> unsupported Unicode code range
>
> does anyone have any idea on what could be going wrong?  The string
> that I store in the database table is:
>
> 'Keinen Text für Übereinstimmungsfehler gefunden'

$ more test.py
# -*- coding: iso-8859-1 -*-
u = u'Keinen Text für Übereinstimmungsfehler gefunden'
s = u.encode("iso-8859-1")
u = s.decode("utf-8") # <-- this gives an error

$ python test.py
Traceback (most recent call last):
  File "test.py", line 4, in ?
    u = s.decode("utf-8") # <-- this gives an error
  File "lib/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 13-18:
unsupported Unicode code range

> I thought that all strings were stored in unicode in sqlite.

did you pass in a Unicode string or an 8-bit string when you stored the text ?

</F> 






More information about the Python-list mailing list