Re: Character Encoding Question

Поиск
Список
Период
Сортировка
От Daniele Varrazzo
Тема Re: Character Encoding Question
Дата
Msg-id CA+mi_8a2kOnqEV2MRw+ZxNUoTma1mBif-aiqsm_-WQoTQa_HWA@mail.gmail.com
обсуждение исходный текст
Ответ на Character Encoding Question  (Don Parris <parrisdc@gmail.com>)
Ответы Re: Character Encoding Question  (Don Parris <parrisdc@gmail.com>)
Список psycopg
Please keep the mailing list in copy.

On Thu, Mar 28, 2013 at 5:17 PM, Don Parris <parrisdc@gmail.com> wrote:
> Here is the result of the query you suggested:
>
>>>> cur = con.cursor()
>>>> cur.execute("show client_encoding")
>>>> print(cur.fetchone()[0])
> SQL_ASCII

This means that everything is going as expected: connection has been
requested in ascii and obtained so. I'll check if really the encoding
errors happen inconsistently in the fetch*() methods. What I suspect
is that you issued fetchone() and got an ascii-only record: if you
continued to loop on the entire recordset you'd eventually get an
error. Try (without setting the encoding to utf8):

    cur.execute("select [ your stuff, including non-ascii records")
    while 1:
        record = cur.fetchone()
        if not record:
            break

I'm pretty sure you will get an encoding error too.


> I created the DB in postgresql using the following command:
> CREATE DATABASE mydb
>     WITH TEMPLATE template0 ENCODING 'UTF8';
>
> Although I cannot now recall my reason for doing so, there *is* a reason why
> I'm using this approach.  :-/  I should have said "why" in my comments!

I don't see anything wrong here. The only question is what is setting
the connection to SQL_ASCII. Maybe something in postgresql.conf or a
setting of the database user. It's not a psycopg issue anyway: the
driver is following the instructions.

-- Daniele


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

Предыдущее
От: Daniele Varrazzo
Дата:
Сообщение: Re: Character Encoding Question
Следующее
От: Federico Di Gregorio
Дата:
Сообщение: Re: Character Encoding Question