summaryrefslogtreecommitdiff
path: root/glanceclient/common/utils.py
diff options
context:
space:
mode:
authorFlaper Fesp <flaper87@gmail.com>2013-07-11 15:28:49 +0200
committerFlaper Fesp <flaper87@gmail.com>2013-07-29 09:30:44 +0200
commitfd0e1175795ac3a5497dcf72ed250077abaf2ed1 (patch)
treed50d8f030d0e863d74ffc45afa222dfc105a0fca /glanceclient/common/utils.py
parent8d7411d78b87020a7c5765dc294118f24449db0c (diff)
downloadpython-glanceclient-fd0e1175795ac3a5497dcf72ed250077abaf2ed1.tar.gz
Encode error messages before sending them to stdout
When an error with non-ascii characters is caught by glanceclient, it fails at printing it and exists with a UnicodeEncodedError. This patch encodes errors' messages using strutils before sending them to stdout. Fixes bug: #1200206 Change-Id: I4dabcd76ffb258840bd6a66ad23c030f34960e86
Diffstat (limited to 'glanceclient/common/utils.py')
-rw-r--r--glanceclient/common/utils.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py
index 49976ac..c0e65db 100644
--- a/glanceclient/common/utils.py
+++ b/glanceclient/common/utils.py
@@ -202,3 +202,15 @@ def getsockopt(self, *args, **kwargs):
lands in mainstream packages.
"""
return self.fd.getsockopt(*args, **kwargs)
+
+
+def exception_to_str(exc):
+ try:
+ error = unicode(exc)
+ except UnicodeError:
+ try:
+ error = str(exc)
+ except UnicodeError:
+ error = ("Caught '%(exception)s' exception." %
+ {"exception": exc.__class__.__name__})
+ return strutils.safe_encode(error, errors='ignore')