连接和Python中的编码不匹配 [英] Encoding mismatch in connection and Python
问题描述
我在启动Firebird连接时遇到了一些麻烦,这似乎与编码有关.我正在这样连接到数据库( local_copy
是/path/to/database.fdb
):
I am having some troubles getting my Firebird connection to work, and it all seems related to encodings. I am connecting to the database like this (local_copy
is /path/to/database.fdb
):
conn = fdb.connect(dsn=local_copy, user='****', password='****', charset="ISO8859_1")
仅适用于某些字符集.我需要具有 ISO8859_1
字符集,该字符集以前可以使用,但现在不再可用(可能是由于更新).
which only works for certain charsets. I need to have the ISO8859_1
charset, which worked before, but not anymore (perhaps because of an update).
Traceback (most recent call last):
File "sync.py", line 10, in <module>
conn = fdb.connect(dsn=local_copy, user='**', password='**', charset="ISO8859_1")
File "/usr/local/lib/python3.6/site-packages/fdb/fbcore.py", line 848, in connect
"Error while connecting to database:")
fdb.fbcore.DatabaseError: ('Error while connecting to database:\n- SQLCODE: -924\n- bad parameters on attach or create database\n- CHARACTER SET ISO8859_1 is not defined', -924, 335544325)
当我使用 ISO88591
时,连接有效,但是Python对此不满意:
When I use ISO88591
, the connect works, but Python is not happy with that:
Traceback (most recent call last):
File "sync.py", line 10, in <module>
conn = fdb.connect(dsn=local_copy, user='***', password='***', charset="ANSI")
File "/usr/local/lib/python3.6/site-packages/fdb/fbcore.py", line 826, in connect
no_reserve, db_key_scope, no_gc, no_db_triggers, no_linger)
File "/usr/local/lib/python3.6/site-packages/fdb/fbcore.py", line 759, in build_dpb
dpb.add_string_parameter(isc_dpb_user_name, user)
File "/usr/local/lib/python3.6/site-packages/fdb/fbcore.py", line 624, in add_string_parameter
value = value.encode(charset_map.get(self.charset, self.charset))
LookupError: unknown encoding: ISO88591
因此,我认为也许可以在Python中添加别名 ISO88591
.我试图编辑/usr/lib64/python3.6/encodings/aliases.py
,但这似乎没有任何作用.
So, I thought perhaps adding an alias ISO88591
to Python would work. I tried to edit the /usr/lib64/python3.6/encodings/aliases.py
, but that didn't seem to have any effect.
推荐答案
作为在Firebird支持上发布的内容的简短摘要,看起来CentOS上Firebird 2.5.8中的 fbintl
模块是坏了.
As a short summary of what was posted on Firebird-support, it looks the fbintl
module in Firebird 2.5.8 on CentOS is broken.
如Philippe Makowski所述:
As indicated by Philippe Makowski:
对不起,它已损坏,我不知道如何解决它: https://bugzilla.redhat.com/show_bug.cgi?id=1636177
但是Firebird 3可以 https://copr.fedorainfracloud.org/coprs/makowski/firebird/
but Firebird 3 is ok https://copr.fedorainfracloud.org/coprs/makowski/firebird/
https://bugzilla.redhat.com/show_bug中建议的一种可能的解决方法.cgi?id = 1636177 是要降级到2.5.7,还是要继续使用2.5.8,但要用<2.5>中的模块替换其 fbintl
模块.
A possible workaround suggested in https://bugzilla.redhat.com/show_bug.cgi?id=1636177 is to either downgrade to 2.5.7, or to continue using 2.5.8, but replace its fbintl
module with the one from 2.5.7.
这篇关于连接和Python中的编码不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!