运行时错误: 文件的密码错误



使用python's zipfile模块,我无法打开加密的zip文件,我发现压缩类型为99。我可以用WinZip打开它,但我想用python自动化这个过程。

我应该考虑使用 7zip 的命令行还是zipfile模块本身有某种方法来解决问题?谢谢!

RuntimeError                              Traceback (most recent call last)
<ipython-input-43-4c4765b40715> in <module>()
3         print (info.filename, info.date_time, info.file_size, info.compress_type)
4     myzip.setpassword(b'password')
5     with myzip.open('641903.txt','r') as myfile:<-----
6         print(myfile.readline()
641903.txt (2018, 6, 26, 11, 59, 50) 342 99
RuntimeError: Bad password for file '641903.txt'

您只需添加第三个参数即可打开受密码保护的文件

with myzip.open('641903.txt','r', 'password') as myfile:
print(myfile.readline() 

最新更新