用Python反序列化postgres bytea

用Python反序列化postgres bytea,python,pandas,postgresql,Python,Pandas,Postgresql,我试图读取postgres表中存储为bytea的列 遵循此处概述的方法() 我试图将memoryview转换为“真实”值。但是,这将返回以下错误消息: c = db.cursor() c.execute("""select bytea_column from table where bytearray_id_ = 'abc123';""") mview = c.fetchone() TypeError: 'memoryview' ob

我试图读取postgres表中存储为bytea的列

遵循此处概述的方法()

我试图将memoryview转换为“真实”值。但是,这将返回以下错误消息:

c = db.cursor()
c.execute("""select bytea_column from table
where bytearray_id_ = 'abc123';""")
mview = c.fetchone()

TypeError: 'memoryview' object cannot be interpreted as an integer
我还尝试将值读入pandas数据帧,然后尝试反序列化在那里接收到的值。然而,这只是返回一个系列,似乎不能用它做很多事情

dataframe = pd.read_sql_query(bytea_query, db_string)

dataframe["bytea"]
0    [b'\xac', b'\xed', b'\x00', b'\x05', b's', b'r...

有没有其他方法可以做到这一点?

解决方案最终相对简单:

data = dataframe["bytes_"][0]
bytearray = bytearray(data)
bytearray
这将返回一个bytearray对象,其中包含来自postgres的正确反序列化数据