[issue6815] UnicodeDecodeError in os.path.expandvars

Ezio Melotti report at bugs.python.org
Sat Mar 6 16:54:05 CET 2010


Ezio Melotti <ezio.melotti at gmail.com> added the comment:

This is a shorter snippet to reproduce the issue:
import os
os.environ['TEST'] = u'äö'.encode('iso-8859-1')
os.path.expandvars(u'%TEST%a')

If the var is a non-ASCII byte string, and the string passed to expandvars() is Unicode, the var is decoded implicitly using the ASCII codec and the decoding fails.

On Python 3 the situation looks even worse:
import os
os.environ['TEST'] = 'äö'.encode('iso-8859-1');
os.path.expandvars('%TEST%a')

This snippet returns "b'\\xe4\\xf6'a".

----------
priority: normal -> high
versions: +Python 2.7, Python 3.1, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6815>
_______________________________________


More information about the Python-bugs-list mailing list