From 69b4233a7d8ef0750f83aa63ff20b939e996cc4f Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 28 Aug 2018 10:18:26 -0400 Subject: [PATCH] FIX: fix importing backend with non-ascii characters The issue is that the lines coming out of `traceback.format_stack()` are bytes (aka python2 str). This file uses `unicode_literals` so the string literals are unicode. If any of the paths in the stack have non-ascii we get UnicodeDecode exceptions when trying to convert the byte strings to unicode with ascii. The `str` calls will have no effect on python3 and down-cast the unicode to bytes so the operations will work. A better fix would be to sort out what encoding the bytes from `format_stack` are in and convert them to unicode, but this is simpler and is unlikely to make things worse than they were. closes #11955 --- lib/matplotlib/backends/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/__init__.py b/lib/matplotlib/backends/__init__.py index ac7b6301e3e7..33c60d855082 100644 --- a/lib/matplotlib/backends/__init__.py +++ b/lib/matplotlib/backends/__init__.py @@ -12,10 +12,11 @@ _log = logging.getLogger(__name__) backend = matplotlib.get_backend() -_backend_loading_tb = "".join( +# the `str` calls here are to make non-ascii paths work on python2 +_backend_loading_tb = str("").join( line for line in traceback.format_stack() # Filter out line noise from importlib line. - if not line.startswith(' File "