如何通过python3.5从firebird2.5获取pdf/jpg文件?

2024-09-27 22:18:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python3.5来完成这个任务+库fdb。我的剧本:

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)

尝试保存文件后,我收到错误:

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

数据库中的编码字段:Win-1251类型:Blob。在

我怎样才能修好它?在


Tags: importhostexecuteconnectpasswordconselectcursor
1条回答
网友
1楼 · 发布于 2024-09-27 22:18:52

发生此错误是因为blob字段的子类型1(文本)。在

subtypes是:

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.

如果不能将子类型更改为0,则可以尝试将数据转换为原始字节并将其转换为客户端应用程序。在

相关问题 更多 >

    热门问题