Python Unicode to String conversion

Carsten Haese carsten at uniqsys.com
Fri Aug 31 20:33:17 EDT 2007


On Fri, 2007-08-31 at 15:55 -0700, thijs.braem at gmail.com wrote:
> Hi everyone,
> 
> I'm having quite some troubles trying to convert Unicode to String
> (for use in psycopg, which apparently doesn't know how to cope with
> unicode strings).
> 
> The error I keep having is something like this:
> ERREUR:  Séquence d'octets invalide pour le codage «UTF8» : 0xe02063

I'm guessing that you are passing a latin-1 encoded string and pretend
(or psycopg assumes) incorrectly that it's UTF-8 encoded. In latin-1
encoding, 0xe0 is a small letter a with a grave accent, 0x20 is a space,
and 0x63 is a small letter c. While this is a perfectly valid latin-1
encoded character string, it doesn't represent a valid UTF-8 encoded
character string.

It seems that you need to pass a UTF-8 encoded string to the database.
To give you specific advice on how to do that, we'd have to see your
code. For now, I'll give you the generic advice of taking a look at
http://www.amk.ca/python/howto/unicode .

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list