Re: Psycopg and queries with UTF-8 data

From: Jarek Zgoda (jzgoda_at_gazeta.usun.pl)
Date: 10/14/04


Date: Thu, 14 Oct 2004 11:03:36 +0000 (UTC)

Alban Hertroys <alban@magproductions.nl> pisze:

> I have a query that inserts data originating from an utf-8 encoded XML
> file. And guess what, it contains utf-8 encoded characters...
> Now my problem is that psycopg will only accept queries of type str, so
> how do I get my utf-8 encoded data into the DB?
>
> I can't do query.encode('ascii'), that would be similar to:
> >>> x = u'\xc8'
> >>> print x.encode('ascii')
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xc8' in
> position 0: ordinal not in range(128)

Did you try x.encode('utf-8')?

-- 
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/