Psycopg and queries with UTF-8 data

Jarek Zgoda jzgoda at gazeta.usun.pl
Thu Oct 14 07:03:36 EDT 2004


Alban Hertroys <alban at 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/



More information about the Python-list mailing list