[英]Python zipfile: RuntimeError: Bad password for file
使用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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.