This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author july
Recipients docs@python, july
Date 2015-05-01.21:30:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1430515803.94.0.193757537296.issue24110@psf.upfronthosting.co.za>
In-reply-to
Content
In documentation of zipfile.ZipFile.write() there is following notice:

"There is no official file name encoding for ZIP files. If you have unicode file names, you must convert them to byte strings in your desired encoding before passing them to write()."

I understand it as that 'arcname' argument to write() shouldn't be of type str, but rather bytes.

But it is str that works, and bytes that does not:

$ ./python
Python 3.5.0a4+ (default:6f6e78931875, May  1 2015, 23:18:40) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import zipfile
>>> zf = zipfile.ZipFile('foo.zip', 'w')
>>> zf.write('python', 'a')
>>> zf.write('python', b'b')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/july/source/python/Lib/zipfile.py", line 1442, in write
    zinfo = ZipInfo(arcname, date_time)
  File "/home/july/source/python/Lib/zipfile.py", line 322, in __init__
    null_byte = filename.find(chr(0))
TypeError: a bytes-like object is required, not 'str'

(ZipInfo ostensibly attempts to find a zero byte in the filename, but searches instead for a unicode character chr(0). There are several other places in ZipInfo class that assume filename being str rather than bytes.)

I consider this a documentation issue: the notice is misleading. Although maybe there is someone who wants to fix the behavior of ZipInfo to allow bytes filename.
History
Date User Action Args
2015-05-01 21:30:04julysetrecipients: + july, docs@python
2015-05-01 21:30:03julysetmessageid: <1430515803.94.0.193757537296.issue24110@psf.upfronthosting.co.za>
2015-05-01 21:30:03julylinkissue24110 messages
2015-05-01 21:30:03julycreate