I have a .zip file and you want to know the file names inside it. Here is the code:
zip_path = glob.glob(path + '/*.zip')[0] file = open(zip_path, 'r') # opens without error if zipfile.is_zipfile(file): print str(file) # prints to console my_zipfile = zipfile.ZipFile(zip_path) # throws IOError
Here is the trace:
<open file u'/Users/me/Documents/project/uploads/assets/peter/offline_message/offline_imgs.zip', mode 'r' at 0x107b2a150> Traceback (most recent call last): File "/Users/me/Documents/project/admin_dev/proj_name/views.py", line 1680, in get_dps_app_builder_assets link_to_assets_zip = zip_dps_app_builder_assets(server_url, app_slug, button_slugs) File "/Users/me/Documents/project/admin_dev/proj_name/views.py", line 1724, in zip_dps_app_builder_assets my_zipfile = zipfile.ZipFile(zip_path) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 712, in __init__ self._GetContents() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 746, in _GetContents self._RealGetContents() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 779, in _RealGetContents fp.seek(self.start_dir, 0) IOError: [Errno 22] Invalid argument
I am very confused why this is happening since the file is clearly present and is a valid .zip file. The documentation clearly states that you can pass it either a file path or a file-like object, none of which work in my case:
http://docs.python.org/2/library/zipfile#zipfile-objects
source share