Python psycopg2 not in utf-8

后端 未结 2 1949
我寻月下人不归
我寻月下人不归 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: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.

提交回复
热议问题