Does python support working with password protected zip files?

Greg Armer wiqd at codelounge.org
Thu Mar 6 11:23:25 EST 2008


On 3/6/08, Malcolm Greene <python at bdurham.com> wrote:
> I'm new to Python and trying to figure out how to read and write to
>  password protected zip files.
>
>  I can work with plain zip files no problem.
>
>  I've googled this topic and am coming up empty except for a post on
>  Nabbler.com that seemed to imply that password protected zip files
>  may(???) be supported in Python 2.6 and ads for a commercial Windows
>  (only) zip component from chilkat.com.
>
>  Any suggestions?

Hi Malcolm,

I just had to do some with with this myself and eventually resorted to
simply using a popen() call to the system unzip utility with the
-Ppass command line option.

<excerpt from script>

    def _unzipdata(self):
        print "[~] Processing zip file %s..." % self.zipfile
        # Create temporary directory
        os.mkdir('_temp')

        # Unzip password protected zipfile to _temp
        os.chdir('_temp')
        os.popen("unzip -P%s ../%s" % (self.password, self.zipfile), "r")
        return True


While this is not ideal, i could not find any other alternatives.

Hope that helps.

--
Greg Armer

Entropy has us outnumbered.



More information about the Python-list mailing list