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
  • 797
  • 1
  • 10
  • 25

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.
  • 61,146
  • 24
  • 125
  • 222
Cristik
  • 30,989
  • 25
  • 91
  • 127
  • This applies only to legacy weak encryption. For current strong encryption see: https://stackoverflow.com/questions/15553150/python-unzip-aes-128-encrypted-file – Mike Feustel Mar 30 '22 at 05:00