-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
tarfile.open does fails with UnicodeDecodeError if parent dir is unicode #52643
Comments
If any directory higher up in the hierarchy contains unicode chars, tarfile.open fails with UnicodeDecodeError. Attached script reproduces this error. [tmp]% python tarfilefail.py
Traceback (most recent call last):
File "tarfilefail.py", line 9, in <module>
tarfile.open(file_name, 'w')
File "/usr/lib/python2.6/tarfile.py", line 1682, in open
return cls.taropen(name, mode, fileobj, **kwargs)
File "/usr/lib/python2.6/tarfile.py", line 1692, in taropen
return cls(name, mode, fileobj, **kwargs)
File "/usr/lib/python2.6/tarfile.py", line 1527, in __init__
self.name = os.path.abspath(name) if name else None
File "/usr/lib/python2.6/posixpath.py", line 338, in abspath
path = join(os.getcwd(), path)
File "/usr/lib/python2.6/posixpath.py", line 70, in join
path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 17: ordinal not in range(128)
[tmp]% |
It looks like tarfile doesn't support unicode filenames. You should try to encode your input filename to the file system default encoding (sys.getfilesystemencoding()), or avoid using unicode for tar filenames. |
I proposed a workaround, the real bug is that os.path.abspath() doesn't support unicode... And this bug was already fixed 7 weeks ago by r78247 (issue bpo-3426). Python 2.6.5 and 2.7b1 are fixed. So please upgrade :-) |
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: