[New-bugs-announce] [issue26272] `zipfile.ZipFile` fails reading a file object in specific version(s)

Pengyu Chen report at bugs.python.org
Wed Feb 3 03:48:27 EST 2016


New submission from Pengyu Chen:

When passing a file object to `zipfile.ZipFile` for reading it fails in Python 3.5.1 it fails. While the same code in Python 2.7.11 works.
Also loading that specific file directly from file path works in Python 3.5.1.
(Please see the sample testing code below for details)

[pengyu at GLaDOS tmp]$ echo "test message" > testfile
[pengyu at GLaDOS tmp]$ zip testfile.zip testfile
updating: testfile (stored 0%)
[pengyu at GLaDOS tmp]$ file testfile.zip 
testfile.zip: Zip archive data, at least v1.0 to extract
[pengyu at 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 at GLaDOS tmp]$ python2 -c "a = open('testfile.zip'); import zipfile; b = zipfile.ZipFile(a, 'r')"
[pengyu at GLaDOS tmp]$ python -c "import zipfile; b = zipfile.ZipFile('testfile.zip', 'r')"
[pengyu at GLaDOS tmp]$ python --version
Python 3.5.1
[pengyu at GLaDOS tmp]$ python2 --version
Python 2.7.11

----------
components: Library (Lib)
messages: 259459
nosy: Pengyu Chen
priority: normal
severity: normal
status: open
title: `zipfile.ZipFile` fails reading a file object in specific version(s)
type: crash
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26272>
_______________________________________


More information about the New-bugs-announce mailing list