output.tar.gzAWS Comprehend 已创建一个在 S3 存储桶中调用的文件。我正在尝试使用 Python 将此文件加载到内存中并尝试了以下操作:import boto3from io import BytesIOimport gzips3 = boto3.client("s3")obj = s3.get_object(Bucket=BUCKET, Key=KEY)mycontentzip = gzip.GzipFile(fileobj=BytesIO(obj['Body'].read())).read()lines = mycontentzip.decode("utf-8")我还尝试了这篇文章中的解决方案,包括不再需要 BytesIO: Reading contents of a gzip file from a AWS S3 in Python我能够使用这些解决方案返回一个测试文件,该文件不确定.gz我能否正确连接到 S3 存储桶。在所有尝试中,返回的是一个仅包含以下内容的文件:00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x...我正在使用 Python=3.7.7 Boto3=1.10.5我还尝试从 AWS 控制台手动下载文件。奇怪的是,该文件在 MacOS 10.15.6 中解压缩为“.jsonl”文件。但是,在 VScode 中以 JSON 形式查看时打开效果很好。还有其他人遇到过这个问题吗?提前感谢您的任何想法。
1 回答

拉风的咖菲猫
TA贡献1995条经验 获得超2个赞
那是一个 tar.gz 文件,即tar
用算法压缩的存档gzip
。
如果您只是使用 阅读它gzip.GzipFile()
,您仍然有一个需要解释的二进制 tar 存档。
使用tarfile
模块读取它;tar 存档,如 zips,可以包含多个文件,其中之一就是.jsonl
您最终看到的文件。
添加回答
举报
0/150
提交
取消