Issue #8313: traceback.format_exception_only() encodes unicode message to
ASCII with backslashreplace error handler if str(value) failed
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 8d28afc..8cb9e28 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -211,8 +211,14 @@
def _some_str(value):
try:
return str(value)
- except:
- return '<unprintable %s object>' % type(value).__name__
+ except Exception:
+ pass
+ try:
+ value = unicode(value)
+ return value.encode("ascii", "backslashreplace")
+ except Exception:
+ pass
+ return '<unprintable %s object>' % type(value).__name__
def print_exc(limit=None, file=None):