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
Python 3, ZipFile Bug In Chinese #56257
Comments
Python 3, ZipFile Bug In Chinese:
1. In Python3.1.3 can't extract "复件 test.txt" from test.zip
╕┤╝■ test.txt
Traceback (most recent call last):
File "C:\Temp\PythonZipTest\pythonzip.py", line 14, in <module>
main()
File "C:\Temp\PythonZipTest\pythonzip.py", line 11, in main
z.extract(z.namelist()[0])
File "c:\python31\lib\zipfile.py", line 980, in extract
return self._extract_member(member, path, pwd)
File "c:\python31\lib\zipfile.py", line 1023, in _extract_member
source = self.open(member, pwd=pwd)
File "c:\python31\lib\zipfile.py", line 928, in open
% (zinfo.orig_filename, fname))
zipfile.BadZipfile: File name in directory '╕┤╝■ test.txt' and header b'\xb8\xb4\xbc\xfe test.txt' differ.
2011-05-10 import zipfile
import os
def main():
szTestDir = os.path.dirname(__file__)
szFile = os.path.join(szTestDir, 'test.zip')
z = zipfile.ZipFile(szFile)
print(z.namelist()[0])
z.extract(z.namelist()[0])
if __name__ == '__main__':
main() |
This is a duplicate of bpo-10801, issue fixed in Python 3.2 or later by 33543b4e0e5d. Should we backport the fix to Python 3.1, or you can upgrade to Python 3.2? Output with Python 3.2: "╕┤╝■ test.txt". |
But according to the initial report, 3.2 does not give the expected behavior. This zip file actually stores the filename encoded with cp932, which is incorrect according to the specifications of the ZIP format (only cp437 and utf8 are valid) See bpo-10614 for a possible solution: allow users to specify an alternate encoding to handle such invalid files. |
Oh, right. Note: the encoding looks to be GBK, not CP932: >>> '\u590d\u4ef6'.encode('gbk')
b'\xb8\xb4\xbc\xfe'
>>> '\u590d\u4ef6'.encode('gbk').decode('cp437')
'╕┤╝■'
>>> '\u590d\u4ef6'.encode('cp932')
...
UnicodeEncodeError: 'cp932' codec can't encode character '\u590d' ... |
See also bpo-4621. |
This issue is just another example of the issue bpo-10614: I'm closing it as a duplicate. |
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: