gpt4 book ai didi

python - SqlAlchemy + Firebird + FDB 的 UnicodeError

转载 作者:行者123 更新时间:2023-11-28 18:09:43 26 4
gpt4 key购买 nike

我正在尝试显示来自 firebird 3.x 数据库的结果,但得到:

File "/...../Envs/pos/lib/python3.6/site-packages/fdb/fbcore.py", line 479, in b2u return st.decode(charset) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 9: invalid continuation byte

尽管我到处都设置了 utf-8:

# -- coding: UTF-8 -- 

import os

os.environ["PYTHONIOENCODING"] = "utf8"

from sqlalchemy import *

SERVIDOR = "localhost"
BASEDATOS_1 = "db.fdb"

PARAMS = dict(
user="SYSDBA",
pwd="masterkey",
host="localhost",
port=3050,
path=BASEDATOS_1,
charset='utf-8'
)

firebird = create_engine("firebird+fdb://%(user)s:%(pwd)s@%(host)s:%(port)d/%(path)s?charset=%(charset)s" % PARAMS, encoding=PARAMS['charset'])

def select(eng, sql):
with eng.connect() as con:
return eng.execute(sql)

for row in select(firebird, "SELECT * from clientes"):
print(row)

最佳答案

我遇到了同样的问题。
在我的情况下,数据库不是 UTF-8。在连接字符串中设置正确的字符集后它起作用了:?charset=ISO8859_1

关于python - SqlAlchemy + Firebird + FDB 的 UnicodeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51432962/

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