Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
apiszcz opened this issue Jun 18, 2016 · 4 comments
Labels

Comments

@apiszcz
Copy link

apiszcz commented Jun 18, 2016

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)

@dvarrazzo
Copy link
Member

In what language is this postgres installation?

@apiszcz
Copy link
Author

apiszcz commented Jul 7, 2016

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

On Thu, Jul 7, 2016 at 7:19 AM, Daniele Varrazzo notifications@github.com
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
#442 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABXVTSRMgKe2pxXExI1A9Pp7j08cl8jdks5qTOCngaJpZM4I5CRM
.

@dvarrazzo
Copy link
Member

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.

@jleclanche
Copy link

jleclanche commented Feb 11, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants