I'm writing a small Python application that reads data from a Firebird database.
I'm using fdb 1.8 and Firebird Embedded 2.5.
I'm not able to decode the following string:
//centrale/Danea Easyfatt/ANYMA 2017 dal 06-02-17.eft
I keep getting this Exception:
Traceback (most recent call last):
File "C:\Matteo\PyCharm\CMakeR\God.py", line 165, in openDBFromMenu
self.openDB(False)
File "C:\Matteo\PyCharm\CMakeR\God.py", line 147, in openDB
while (self.dbManager.connectTo(path)==False):
File "C:\Matteo\PyCharm\CMakeR\DBManager.py", line 36, in connectTo
charset="WIN1252"
File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\fdb\fbcore.py", line 736, in connect
"Error while connecting to database:")
File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\fdb\fbcore.py", line 562, in exception_from_status
msglist.append('- ' + (msg.value).decode('utf_8'))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 38: invalid continuation byte
What should I do?
I've already tried decoding and encoding in WIN1252 and other formats.
I'm scratching my head.
You need to set charset in connection to database.
For example, using fdb package you need to set charset parameter:
import fdb
con = fdb.connect(
dsn='bison:/temp/test.db',
user='sysdba', password='pass',
charset='WIN1251' # specify a correct character set for the connection
)
Using sqlalchemy you can set it in database_uri:
from sqlalchemy import create_engine
firebird = create_engine("firebird+fdb://%(user)s:%(pwd)s@%(host)s:%(port)/%(path)s?charset=%(charset)s"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With