How to open password protected zip file in Python 3

拟墨画扇 提交于 2019-12-11 10:48:58

问题


I'm trying to open a password protected zip file in Python. However, I'm completely stuck!

I've gone through the python documentation on zip files, but I can't find anything for opening one that is password protected.

Could someone please point me in the right direction?

path = "some_file.zip"
password = "example123"

# How do I add the password parameter?
ZipFile.extractall(path)

回答1:


From https://docs.python.org/2/library/zipfile.html:

ZipFile.extractall([path[, members[, pwd]]])

Extract all members from the archive to the current working directory. path specifies a different directory to extract to. members is optional and must be a subset of the list returned by namelist(). pwd is the password used for encrypted files.

Works on Python 3 too: https://docs.python.org/3/library/zipfile.html



来源:https://stackoverflow.com/questions/29631629/how-to-open-password-protected-zip-file-in-python-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!