在作为守护进程运行的Python脚本中解压文件时出错

0 投票
2 回答
1864 浏览
提问于 2025-04-15 23:24

我在运行一个Python脚本时遇到错误,这个脚本是作为守护进程在后台运行的。每当我尝试执行下面的解压命令时,就会出错。

命令:

unzip abcd.zip > /dev/null

错误信息:

End-of-central-directory signature not found$ a zip file, or it 
constitutes one disk of a multi-part archive. In the latter case
the central directory and zipfile comment will be found on the last 
disk(s) of this archive

unzip:  cannot find zipfile directory in one of abcd.zip$
        abcd.zip.zip, and cannot find abcd.zip.ZIP, period.

有人能帮我解决这个问题吗?

提前谢谢大家。

2 个回答

0

首先要检查一下文件。这看起来像是一个损坏或无效的压缩文件。

1

通常这句话的意思就是:文件 abcd.zip 不是一个有效的ZIP文件。你能作为普通用户解压 abcd.zip 吗?如果不能,那可能这个文件已经损坏了。你是怎么得到这个文件的?检查一下是否有像ASCII模式FTP这样的操作导致了文件格式出错。

你能用Python自带的 zipfile 模块读取这个文件吗?在Python中直接处理文件通常比把它扔到命令行里更好。

撰写回答