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

2016-02-03 Thread Pengyu Chen

Pengyu Chen added the comment:

Oh yes you're right Martin. Thanks for the notice :) (I've closed this ticket 
before seeing your reply)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-02-03 Thread Martin Panter

Martin Panter added the comment:

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 :)

--
nosy: +martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-02-03 Thread Pengyu Chen

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@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 "", line 1, in 
  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

--
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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2016-02-03 Thread Pengyu Chen

Pengyu Chen added the comment:

Well I should have noticed that I wasn't using binary mode.. Sorry for the 
mistake. Closing the issue report.

--
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com