Convertion of Unicode to ASCII NIGHTMARE

Serge Orlov Serge.Orlov at gmail.com
Mon Apr 10 04:56:13 EDT 2006


ChaosKCW wrote:
> Roger Binns wrote:
>
> >
> > No.  APSW converts it *to* Unicode.  SQLite only accepts Unicode
> > so a Unicode string has to be supplied.  If you supply a non-Unicode
> > string then conversion has to happen.  APSW asks Python to
> > supply the string in Unicode.  If Python can't do that (eg
> > it doesn't know the encoding) then you get an error.
>
> If what you say is true, I have to ask why I get a converstion error
> which states it cant convert to ASCII, not it cant convert to UNICODE?

You do get error about convertion to unicode. Quote from you message:

>    SQLiteCur.execute(sql, row)
>UnicodeDecodeError: 'ascii' codec can't decode byte 0xdc in position 12: ordinal not in >range(128)

Notice the name of the error: UnicodeDecode or in other words
ToUnicode.


>  So I am missing how a
> function which supposedly converts evereythin to unicode lands up doing
> an ascii converstion ?

When python tries to concatenate a byte string and a unicode string, it
assumes that the byte string is encoded ascii and tries to convert from
encoded ascii to unicode. It calls ascii decoder to do the decoding. If
decoding fails you see message from ascii decoder about the error.

   Serge




More information about the Python-list mailing list