700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python 解压zip密码正确但解压失败_在Python中用密码解压zip文件失败的bug?

python 解压zip密码正确但解压失败_在Python中用密码解压zip文件失败的bug?

时间:2023-06-18 23:00:23

相关推荐

python 解压zip密码正确但解压失败_在Python中用密码解压zip文件失败的bug?

我在python中得到一个奇怪的错误。当我尝试使用zip模块提取受密码保护的文件时,当尝试将“oy”设置为密码时出现异常。其他一切似乎都起作用了。ZipFile模块中的错误?import zipfile

zip = zipfile.ZipFile("file.zip", "r")

zip.setpassword("oy".encode('utf-8'))

zip.extractall() #Above password "oy" generates the error here

zip.close()

这是我得到的例外:Traceback (most recent call last):

File "unzip.py", line 4, in

zip.extractall()

File "C:\Program Files\Python32\lib\zipfile.py", line 1002, in extrac

l

self.extract(zipinfo, path, pwd)

File "C:\Program Files\Python32\lib\zipfile.py", line 990, in extract

return self._extract_member(member, path, pwd)

File "C:\Program Files\Python32\lib\zipfile.py", line 1035, in _extra

member

shutil.copyfileobj(source, target)

File "C:\Program Files\Python32\lib\shutil.py", line 65, in copyfileo

buf = fsrc.read(length)

File "C:\Program Files\Python32\lib\zipfile.py", line 581, in read

data = self.read1(n - len(buf))

File "C:\Program Files\Python32\lib\zipfile.py", line 633, in read1

max(n - len_readbuffer, self.MIN_READ_SIZE)

zlib.error: Error -3 while decompressing: invalid block type

如果使用UTF-16作为编码,则会出现以下错误:zlib.error: Error -3 while decompressing: invalid distance too far back

编辑

我现在已经在一台虚拟Linux机器上进行了以下测试:Python版本:2.6.5

我用zip -e file.zip

hello.txt创建了一个受密码保护的zip文件

现在看来问题出在别的地方了。现在我可以提取zip文件,即使密码是错误的!try:

zip.setpassword("ks") # "ks" is wrong password but it still extracts the zip

zip.extractall()

except RuntimeException:

print "wrong!"

有时我可以用不正确的密码提取zip文件。然后提取文件(在zip文件中),但当我试图打开它时,信息似乎已损坏/解密。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。