Re: Character Encoding Question

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Don Parris <parrisdc(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Character Encoding Question
Date: 2013-03-28 17:30:00
Message-ID: CA+mi_8a2kOnqEV2MRw+ZxNUoTma1mBif-aiqsm_-WQoTQa_HWA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Please keep the mailing list in copy.

On Thu, Mar 28, 2013 at 5:17 PM, Don Parris <parrisdc(at)gmail(dot)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

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Don Parris 2013-03-28 17:38:57 Re: Character Encoding Question
Previous Message Federico Di Gregorio 2013-03-28 17:12:11 Re: Character Encoding Question