Re: latin-1 to utf8 in python

Поиск
Список
Период
Сортировка
От Tino Wildenhain
Тема Re: latin-1 to utf8 in python
Дата
Msg-id 44D1A08C.9090306@wildenhain.de
обсуждение исходный текст
Ответ на latin-1 to utf8 in python  (anil maran <anilmrn@yahoo.com>)
Список pgsql-www
anil maran schrieb:
> postgres takes utf8
> pls help me solve this thanks a lot
> some data is in latin-1 so postgres
> crashes

hm. "crashes" isnt quite correct, it
would "bark" or something, however ;)


> with
> psycopg2.ProgrammingError at /todo/38
> invalid byte sequence for encoding "UTF8": 0x92
> ariable         Value
> args
> ("INSERT INTO xdaad(nt, nn, tadadid, email) VALUES (%s, %s, %s, %s); SELECT
> currval('comments_id_seq')", ['co-worker\x92snd I\x92ll get the
> .\r\n\r\n \r\n\r\nAeF\r\n\r\n\r\n\r\n \r\n\r\n', '121', '38', '...
>
<http://groups.google.com/groups/unlock?msg=ead2077185e3de4c&_done=/group/webpy/browse_thread/thread/22297f1549fc41b2/ead2077185e3de4c>@tad.com'])

>
> <http://groups.google.com/group/webpy/browse_thread/thread/22297f1549fc41b2/ead2077185e3de4c#>

Well you either recode in python:

latin1string.decode('iso-8859-1').encode('utf-8')

or set your client-encoding for postgres, so
postgres does the conversion.

Look into psycopg api how to do this on connect
or just issue:

"SET CLIENT_ENCODING TO 'iso-8859-1'"
just after connect.

Regards
Tino Wildenhain

В списке pgsql-www по дате отправления:

Предыдущее
От: "Marc G. Fournier"
Дата:
Сообщение: Re: pugs.postgresql.org is down
Следующее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: jabber.postgresql.org ...