1

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)
Jonty Morris
  • 735
  • 1
  • 10
  • 23

1 Answers1

2

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

Artjom B.
  • 59,901
  • 24
  • 121
  • 211
Cristik
  • 28,596
  • 24
  • 84
  • 120
  • This applies only to legacy weak encryption. For current strong encryption see: https://stackoverflow.com/questions/15553150/python-unzip-aes-128-encrypted-file – Mike F. Mar 30 '22 at 05:00