gpt4 book ai didi

Python psycopg2 不在 utf-8 中

转载 作者:太空狗 更新时间:2023-10-30 01:57:11 24 4
gpt4 key购买 nike

我使用 Python 像这样连接到我的 postgresql 数据库:

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

没问题。

但是当我进行查询并且我想打印光标时,我有这样的东西:

“Fran\xc3\xa7ois”而不是“François”,当我想用​​它创建 XML 文档时它会导致问题。我认为来 self 的编码,但我找到了任何解决方案。我尝试编码('utf-8')但不起作用。

我也看到过类似的东西,但它只适用于 mySQL

MySQLdb.connect(charset='utf8', init_command='SET NAMES UTF8')

你能帮帮我吗?谢谢

最佳答案

通过运行确保您使用正确的编码:print conn.encoding,如果需要,您可以通过 conn.set_client_encoding('UNICODE') 设置正确的编码,或 conn.set_client_encoding('UTF8')

关于Python psycopg2 不在 utf-8 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43583285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com