summaryrefslogtreecommitdiff
path: root/keystoneclient/session.py
diff options
context:
space:
mode:
authorTrevor McKay <tmckay@redhat.com>2016-02-09 13:40:39 -0500
committerTrevor McKay <tmckay@redhat.com>2016-02-10 14:04:47 -0500
commit96fbfeab973cf61cd5ba129056cf4e6634d805b8 (patch)
treea78bb0855674b81b6fab7cc6c957d80108de867c /keystoneclient/session.py
parent81f7fea507025229ba258d7ec7467867fe014438 (diff)
downloadpython-keystoneclient-96fbfeab973cf61cd5ba129056cf4e6634d805b8.tar.gz
Handle exception on UnicodeDecodError in logging of request
If the logging of an HTTP request causes a UnicodeDecodeError, modify the log entry using oslo_utils.encodeutils.safe_decode with errors='replace' and try again Co-Authored-By: Nikita Konovalov <nkonovalov@mirantis.com> Change-Id: Ic365c654ebca4045208c6c30e232665145db7b4c Closes-Bug: #1453953
Diffstat (limited to 'keystoneclient/session.py')
-rw-r--r--keystoneclient/session.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/keystoneclient/session.py b/keystoneclient/session.py
index 7c35247..35ccbda 100644
--- a/keystoneclient/session.py
+++ b/keystoneclient/session.py
@@ -22,6 +22,7 @@ import warnings
from debtcollector import removals
from oslo_config import cfg
from oslo_serialization import jsonutils
+from oslo_utils import encodeutils
from oslo_utils import importutils
from oslo_utils import strutils
from positional import positional
@@ -192,10 +193,18 @@ class Session(object):
for header in six.iteritems(headers):
string_parts.append('-H "%s: %s"'
% self._process_header(header))
+
if data:
string_parts.append("-d '%s'" % data)
-
- logger.debug(' '.join(string_parts))
+ try:
+ logger.debug(' '.join(string_parts))
+ except UnicodeDecodeError:
+ logger.debug("Replaced characters that could not be decoded"
+ " in log output, original caused UnicodeDecodeError")
+ string_parts = [
+ encodeutils.safe_decode(
+ part, errors='replace') for part in string_parts]
+ logger.debug(' '.join(string_parts))
def _http_log_response(self, response, logger):
if not logger.isEnabledFor(logging.DEBUG):