Python Zipfile - Invalid Errno Argument 22

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

+6
source share
1 answer

I was not able to understand this problem and it ended completely differently.

EDIT: in the Django application I'm working with, users should be able to upload assets as .zip files, and then upload everything they have downloaded (plus other content that we generate dynamically), to another email program with a different structure, Therefore, I wanted to unzip the previously downloaded file and fix the contents of this file to another zip file, which I could not do due to an error. Instead of reading the zip file when the user requested a download, I in turn unzipped it from the Django InMemoryUploadedFile (the contents of which I could successfully read) and simply left the unpacked files in the file system for work later. The zip content is just two small image files, so this temporary solution to unzip the zip file, which will be used later, works fine for my purposes.

-2
source

All Articles