psycopg2 icon indicating copy to clipboard operation
psycopg2 copied to clipboard

Encoding question: SystemError: 'cp1252', Python 3.5, psycopg2 '2.6.1 (dt dec pq3 ext lo64)'

Open apiszcz opened this issue 9 years ago • 4 comments

Is there an explicit encoding requirement that I need to set? Thanks

cur.execute("""CREATE DATABASE IF NOT EXISTS TEST""") *** SystemError: decoding with 'cp1252' codec failed (SystemError: returned a result with an error set)

apiszcz avatar Jun 18 '16 21:06 apiszcz

In what language is this postgres installation?

dvarrazzo avatar Jul 07 '16 11:07 dvarrazzo

English on Windows 10 i switched to PostgreSQL no issues.​

On Thu, Jul 7, 2016 at 7:19 AM, Daniele Varrazzo [email protected] wrote:

In what language is this postgres installation?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/psycopg/psycopg2/issues/442#issuecomment-231050826, or mute the thread https://github.com/notifications/unsubscribe/ABXVTSRMgKe2pxXExI1A9Pp7j08cl8jdks5qTOCngaJpZM4I5CRM .

apiszcz avatar Jul 07 '16 17:07 apiszcz

The above causes an error because "create database if not exists" doesn't exist.

In [11]: cnn.set_client_encoding('win1252')

In [12]: cur.execute("create database if not exists asdf ")
---------------------------------------------------------------------------
ProgrammingError                          Traceback (most recent call last)
<ipython-input-12-8557d908ff45> in <module>()
----> 1 cur.execute("create database if not exists asdf ")

ProgrammingError: syntax error at or near "not"
LINE 1: create database if not exists asdf 
                           ^

I believe this message gets localized in a locale that has chars not supported in cp1252, which postgres emits anyway but python then barfs trying to decode, in a codepath that doesn't handle the exception properly. I should make myself a Japanese database to play with...

However if you say that postgres is in English for you, then my theory doesn't work here because, as you see above there is no problem receiving the exception in English.

dvarrazzo avatar Jul 07 '16 18:07 dvarrazzo

@dvarrazzo I think it's the other way around, python is in cp1252, postgres is in utf8.

jleclanche avatar Feb 11 '18 06:02 jleclanche