[ python-Bugs-878120 ] Zipfile archive name can't be unicode

SourceForge.net noreply at sourceforge.net
Sat Jan 17 18:56:57 EST 2004


Bugs item #878120, was opened at 2004-01-16 10:32
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=878120&group_id=5470

Category: Extension Modules
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Simon Harrison (ssmmhh)
Assigned to: Nobody/Anonymous (nobody)
Summary: Zipfile archive name can't be unicode

Initial Comment:
In Python 2.3.2, The following code:

import zipfile
z = zipfile.ZipFile( "file.zip", "w" )
z.write( "file.txt", u"file.txt" )
z.close()

Results in this exception:

Traceback (most recent call last):
  File "E:\dev\ziptest.py", line 8, in ?
    z.write( "file.txt", u"file.txt" )
  File "D:\Python23\lib\zipfile.py", line 412, in write
    self.fp.write(zinfo.FileHeader())
  File "D:\Python23\lib\zipfile.py", line 166, in FileHeader
    return header + self.filename + self.extra
UnicodeDecodeError: 'ascii' codec can't decode byte 
0xd5 in position 10: ordinal
 not in range(128)

The code could be fixed in zipfile.py.

Something along the lines of:
return header + self.filename.encode("utf-8") + self.extra

On Windows ideally the code should figure out the 
current locale's codepage and use that to encode the 
filename into the correct multibyte sequence.

The example above is pretty easy to spot, but if the 
arcname is coming from a COM property (my case) it 
takes a while to figure out why zipfile is crashing!

This is bug 705295 resubmitted:

https://sourceforge.net/tracker/?
func=detail&atid=105470&aid=705295&group_id=5470 





----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2004-01-18 00:56

Message:
Logged In: YES 
user_id=21627

Using UTF-8 is incorrect. Names in zip files are stored in
code page 437. There is no support for file names outside
this character set.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=878120&group_id=5470



More information about the Python-bugs-list mailing list