【发布时间】:2019-02-25 18:29:21
【问题描述】:
我想在 postgres 数据库中存储一个 zip 文件。列类型为bytea
当尝试获取 json 文件或 csv 文件的字节时,我可以使用它
with open(filename, encoding='utf-8') as file_data:
bytes_content = file_data.read()
但是,如果我尝试使用 zip 文件,甚至是 xls 文件,我会收到错误消息。
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd7 in position 14: invalid continuation byte
我做了一些搜索,有人建议更改编码类型,我尝试了latin-1 和ISO-8859-1,这两个都给我一个错误。
ValueError: A string literal cannot contain NUL (0x00) characters.
关于如何获取 zip 文件的字节以便我可以将其存储在 postgres 数据库中的任何想法?
【问题讨论】:
标签: excel python-3.x postgresql zipfile