2

I use Python 3.5 for this task + library fdb. My script:

import fdb
con = fdb.connect(
    host='host', database='database',
    user='IAKUZNETSOV', password='111111'
  )
cur = con.cursor()
cur.execute("select DATA from ATTACHMENTS where OID = '6512165313'")
fileToSave= cur.fetchone()[0]
with open('c:\\python5.jpg', 'wb') as f:
    f.write(fileToSave)

After attempts to save the file I receive error:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 578: character maps to <undefined>

Encoding fields in the database: Win-1251 type: Blob.

How can I fix it?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

1

This error occurs because the subtype 1(text) of blob field.

The subtypes are:

0 - binary data (image, video, audio, whatever)

1 - text (basiccharacter functions work)

2 - BLR (used for definitions of Firebird procedures, triggers, etc.)

User applications should only use subtypes 0 and 1.

If you can not change subtype to 0, you may try to convert the data into raw bytes into client application.

Community
  • 1
  • 1
Val Marinov
  • 2,705
  • 17
  • 22