Python psycopg2 not in utf-8

后端 未结 2 1950
我寻月下人不归
我寻月下人不归 2021-01-05 11:03

I use Python to connect to my postgresql data base like this:

conn=psycopg2.connect(database=\"fedour\", user=\"fedpur\", password=\"***\", host=\"127.0.0.1\         


        
相关标签:
2条回答
  • 2021-01-05 11:03

    Make sure you're using the right encodind by running: print conn.encoding, and if you need, you can set the right encoding by conn.set_client_encoding('UNICODE'), or conn.set_client_encoding('UTF8').

    0 讨论(0)
  • 2021-01-05 11:22

    Does the value get inserted correctly when query is executed via command prompt?

    If yes, then the problem is with your cursor execution.Try cur.execute(u"querystring");(The u indicates utf encoding)

    If no, then you need to set the encoding type of postgres to consider utf-8. You can refer character encoding in Postgres to see how to set default character encoding for a database, and on-the-fly conversion from one encoding to another.

    0 讨论(0)
提交回复
热议问题