我有一个目录列表,其中包含子目录。在每个子目录中都有一些'json.xz‘压缩文件。如果我试图用我的代码打开它们中的一个,我会得到错误:
raise EOFError("Compressed file ended before the "
EOFError: Compressed file ended before the end-of-stream marker was reached这是我的代码:
subject = 'AntonioGio'
path = '/home/rootdebian/Scrivania/Socialisys/projects/'+subject+'/competitor/'
for competitors in os.listdir(path):
for f in os.listdir(path+competitors):
if f.endswith('.xz'):
with lzma.open(path+competitors+'/'+f) as f:
json_bytes = f.read()
stri = json_bytes.decode('utf-8')
data = json.loads(stri)
print(data)修复它的最好方法是什么?谢谢你的建议。
发布于 2020-04-20 13:08:28
这可能是因为您拥有的压缩数据文件不完整/损坏。您提供的代码可以很好地解压json.xz文件。
https://stackoverflow.com/questions/61141780
复制相似问题