3

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.

  • Where is that string coming from? On the face of it, that string does not contain a byte 0xe8 (eg in Windows-1252, 0xe8 is è), so this is likely not the actual string, or your problem is elsewhere. Please provide sufficient code and information to reproduce the problem. Also, if your problem is with that string, then how does this have anything to do with FDB or Firebird 2.5 Embedded? – Mark Rotteveel Mar 14 '18 at 17:02
  • what is the charset of your connection and what is charset of data column? You do not have to decode anything, you have to tell firebird to pass you data in the format you(python) want to work with – Arioch 'The Mar 14 '18 at 17:05
  • @MarkRotteveel I got that string from a qt file dialog and then I printed it in the console. It is an actual file located on CENTRALE. What kind code should I provide? Connections with other files do work. –  Mar 14 '18 at 17:08
  • @Arioch'The My connection charset is WIN1252. –  Mar 14 '18 at 17:09
  • 1
    @Arioch'The This problem seems to be before connecting to a database – Mark Rotteveel Mar 14 '18 at 17:17
  • I don't know which code you need to provide, because you are not giving enough to go on. Start by posting the full stacktrace and provide relevant code listed in that stacktrace. – Mark Rotteveel Mar 14 '18 at 17:18
  • @MarkRotteveel you are right. Thanks for the input. –  Mar 14 '18 at 17:24
  • First of all, is "the following string" a database file (Connection string) ? Then it looks very wrong! https://stackoverflow.com/questions/49067815/opening-a-gdb-file-on-a-network-share – Arioch 'The Mar 15 '18 at 15:48
  • Also, try to change connection charset to UTF-8 - my blind guess is that your Firebird Client DLL is reporting you it cannot connect to remote Named Pipes connected server, and this error message your FB library can not parse. I hope that if u set c-tion cs to UTF-8 than fbClient.DLL would use UTF-8 for error messages and your lib would parse it. – Arioch 'The Mar 15 '18 at 15:50
  • @Arioch'The nope. Nothing changes. –  Mar 15 '18 at 16:23
  • well, anyway with such a connection string u have almost zero chances to attach to the database server – Arioch 'The Mar 16 '18 at 08:32
  • @Arioch'The why? I have enabled connections to UNC paths in Firebird configuration. –  Mar 17 '18 at 10:45
  • Did you find a solution? – Geovani Ferreira Feb 28 '19 at 19:39
  • @GeovaniFerreira Unfortunately no. I stop using UNC paths for that application. –  Mar 04 '19 at 08:42

1 Answers1

1

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"
HelenShy
  • 306
  • 1
  • 7