我有几个 Oracle 中的 blob 图像,所以我用 Python 读取它们。
使用我的代码,我可以正确地从某个表格 table1 中读取和转换图像,但是当我切换到 table2 时,我无法执行相同的代码,因为我得到以下错误:
无法识别图像文件 <_io.BytesIO object at 0x000000000C4520A0>
这是我的代码:
import pandas as pd
import cx_Oracle
from PIL import Image
#[connection to database with connecting string `conn`]
#[query to acces 1 single image]
result = pd.read_sql(query, conn) #connection to db
img = result["IMAGE"][0].read() # reading the first BLOB result
pre_img = io.BytesIO(img)
Image.open(pre_img)
这段代码运行良好,唯一的问题是我尝试从table1中读取图片时出现了问题。在SQL开发人员中,我可以预览table1中的照片,但不能预览table2。 数据类型是Oracle中的BLOB,如describe(table)所述。
img
的值可以在此处找到。