簡體   English   中英

Python zipfile:RuntimeError:文件密碼錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM