-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
zipfile.ZipFile
fails reading a file object in specific version(s)
#70460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
When passing a file object to [pengyu@GLaDOS tmp]$ echo "test message" > testfile
[pengyu@GLaDOS tmp]$ zip testfile.zip testfile
updating: testfile (stored 0%)
[pengyu@GLaDOS tmp]$ file testfile.zip
testfile.zip: Zip archive data, at least v1.0 to extract
[pengyu@GLaDOS tmp]$ python -c "a = open('testfile.zip'); import zipfile; b = zipfile.ZipFile(a, 'r')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.5/zipfile.py", line 1026, in __init__
self._RealGetContents()
File "/usr/lib/python3.5/zipfile.py", line 1093, in _RealGetContents
raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file
[pengyu@GLaDOS tmp]$ python2 -c "a = open('testfile.zip'); import zipfile; b = zipfile.ZipFile(a, 'r')"
[pengyu@GLaDOS tmp]$ python -c "import zipfile; b = zipfile.ZipFile('testfile.zip', 'r')"
[pengyu@GLaDOS tmp]$ python --version
Python 3.5.1
[pengyu@GLaDOS tmp]$ python2 --version
Python 2.7.11 |
I think you are only meant to pass in a “binary” (bytes) file object. Maybe BufferedIOBase, I’m not sure. The documentation doesn’t seem to make this very clear though. Can you suggest an improvement? Open the file with a = open("testfile.zip", "rb") and all should be well :) |
Well I should have noticed that I wasn't using binary mode.. Sorry for the mistake. Closing the issue report. |
Oh yes you're right Martin. Thanks for the notice :) (I've closed this ticket before seeing your reply) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: