Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8406281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:04:03+00:00 2026-06-09T23:04:03+00:00

I am using python’s standard library, zipfile, to test an archive: zf = zipfile.ZipFile(archive_name)

  • 0

I am using python’s standard library, zipfile, to test an archive:

zf = zipfile.ZipFile(archive_name)
if zf.testzip()==None: checksum_OK=True

And I am getting this Runtime exception:

File "./packaging.py", line 36, in test_wgt
    if zf.testzip()==None: checksum_OK=True
  File "/usr/lib/python2.7/zipfile.py", line 844, in testzip
    f = self.open(zinfo.filename, "r")
  File "/usr/lib/python2.7/zipfile.py", line 915, in open
    "password required for extraction" % name
RuntimeError: File xxxxx/xxxxxxxx.xxx is encrypted, password required for extraction

How can I test, before I run testzip(), if the zip is encrypted? I didn’t found an exception to catch that would make this job simpler.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:04:04+00:00Added an answer on June 9, 2026 at 11:04 pm

    A quick glance at the zipfile.py library code shows that you can check the ZipInfo class’s flag_bits property to see if the file is encrypted, like so:

    zf = zipfile.ZipFile(archive_name)
    for zinfo in zf.infolist():
        is_encrypted = zinfo.flag_bits & 0x1 
        if is_encrypted:
            print '%s is encrypted!' % zinfo.filename
    

    Checking to see if the 0x1 bit is set is how the zipfile.py source sees if the file is encrypted (could be better documented!) One thing you could do is catch the RuntimeError from testzip() then loop over the infolist() and see if there are encrypted files in the zip.

    You could also just do something like this:

    try:
        zf.testzip()
    except RuntimeError as e:
        if 'encrypted' in str(e):
            print 'Golly, this zip has encrypted files! Try again with a password!'
        else:
            # RuntimeError for other reasons....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using python 2.4 and the built-in ZipFile library, I cannot read very large zip
Im using python to access a MySQL database and im getting a unknown column
Using python 2.6.5 on Windows XP, it seems I'm getting the wrong result when
Using Python's Networkx library, I created an undirected graph to represent a relationship network
Using Python regular expressions how can you get a True / False returned? All
Using Python 2.5 and httplib...... I am admittedly a python novice.....but this seems straight
(Using Python 2.7) I understand this is pretty elementary but why wouldn't the following
Using Python's Imaging Library I want to create a PNG file. I would like
Using Python, I'm trying to parse a string like this: hello I am an
(Using Python 3.1) I know this question has been asked many times for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.