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
Unicode decode error [backport to 1.4.x] #3594
Conversation
@@ -523,7 +523,7 @@ def _get_home(): | |||
http://mail.python.org/pipermail/python-list/2005-February/325395.html | |||
""" | |||
try: | |||
path = os.path.expanduser("~") | |||
path = os.path.expanduser(b"~").decode(sys.getfilesystemencoding()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a tad confused why this goes through a byte string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On 9/29/2014 20:42, Thomas A Caswell wrote:
In lib/matplotlib/init.py:
@@ -523,7 +523,7 @@ def _get_home():
http://mail.python.org/pipermail/python-list/2005-February/325395.html
"""
try:
path = os.path.expanduser("~")
path = os.path.expanduser(b"~").decode(sys.getfilesystemencoding())
I am a tad confused why this goes through a byte string
—
Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/3594/files#r18174163.I got the idea from a comment in this thread:
https://stackoverflow.com/questions/23888120/an-alternative-to-os-path-expanduser
If I correctly understand what is happening because I pass in b""" or just "~" is used then expanduser will
expanduser returns a byte string, this can then be decoded using the
filesystemencoding, if u"
convert using the sys.defaultencoding.
Hopefully someone with more Python know how then me can confirm that
this is a valid approach - at least on Windows.
See this bug: http://bugs.python.org/issue13207 I just pulled up the code in This PR shouldn't be merged exactly as-is, though. This special workaround should only occur on Windows, and only on Python 2.x. On POSIX, On Python 3, Other than that, looks good to me. Thanks for getting to the bottom of this. |
Hi Thomas, |
Perhaps we should ask some people on the scipy and/or numpy list? They On Tue, Sep 30, 2014 at 9:29 AM, Thomas A Caswell notifications@github.com
|
Or someone from IPython? |
This is consistent with a fix I submitted to PySide (getfilesystemencoding needed on win32 python 2) and it looks correct to me here. I tried to test this a bit on my machine, but I'm foiled on getting a successful login with a user name with an "ä" on my english win7. |
To enter an 'ä' on an English Keyboard hold 'alt' and enter '0228' on the numpad or install a 'de' keyboard. |
Thanks @wernerfb ; I had actually figured that part out. After walking away from my computer & coming back, I realized my problem. It was much more basic (logging onto my domain rather than the local machine); sigh. Now I can review. I can confirm that with "C:\Users\säm" user profile & with-out the PR here I get the UnicodeDecodeError as above. With this PR included, the matplotlib import works. "+1" from me. |
BUG : Unicode decode error on with unicode username on py2+win
BUG : Unicode decode error on with unicode username on py2+win
Should this be cherry-picked onto 1.4.x ? |
I am about to push it up, got distracted by noticing someone (turns out it was me) had deleted the v1.4.0-doc branch and fixing it. |
cherry picked as df4e10a |
Correct the following exception on Windows with Py2.x and user having e.g. Umlaute in his home folder name.
twcbsrc.app_base - ERROR - app_base.pyo - 292 - Traceback (most recent call last):
File "twcbsrc\controllers\app_cb.pyo", line 403, in onTBStats
File "importlib__init__.pyo", line 37, in import_module
File "zipextimporter.pyo", line 82, in load_module
File "twcbsrc\controllers\app_stats.pyo", line 29, in
File "zipextimporter.pyo", line 82, in load_module
File "twcbsrc\views\statistics.pyo", line 19, in
File "zipextimporter.pyo", line 82, in load_module
File "matplotlib__init__.pyo", line 1048, in
File "matplotlib__init__.pyo", line 897, in rc_params
File "matplotlib__init__.pyo", line 759, in matplotlib_fname
File "matplotlib__init__.pyo", line 630, in get_configdir
File "matplotlib__init_.pyo", line 555, in get_xdg_config_dir
File "matplotlib__init_.pyo", line 323, in wrapper
File "matplotlib__init__.pyo", line 509, in _get_home
File "ntpath.pyo", line 310, in expanduser
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 10: invalid start byte
See also: #3532