From dec9c9f3525577dd865bd12d43e4578ae32e4d3c Mon Sep 17 00:00:00 2001 From: Michael Still Date: Tue, 17 Jun 2014 17:45:47 +1000 Subject: [PATCH] Change a debug line to prevent UnicodeDecodeError issue This debug line is causing tracebacks in the n-cpu logs for tempest runs. Its because the logged data is sometimes unicode: Traceback (most recent call last): File "/usr/lib/python2.7/logging/__init__.py", line 846, in emit msg = self.format(record) File "/opt/stack/new/nova/nova/openstack/common/log.py", line 710, in format return logging.StreamHandler.format(self, record) File "/usr/lib/python2.7/logging/__init__.py", line 723, in format return fmt.format(record) File "/opt/stack/new/nova/nova/openstack/common/log.py", line 674, in format return logging.Formatter.format(self, record) File "/usr/lib/python2.7/logging/__init__.py", line 467, in format s = self._fmt % record.__dict__ UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1234: ordinal not in range(128) Logged from file http.py, line 153 The change used correct encoding error handling policy for the log which may includes non-ascii char. Closes-bug: 1320655 Change-Id: I97f5f14b9beddcceb7fbd371062caf5a38a62a20 --- glanceclient/common/http.py | 2 +- tests/test_http.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index 2bc62573..015328db 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -150,7 +150,7 @@ class HTTPClient(object): curl.append('-d \'%s\'' % kwargs['body']) curl.append('%s%s' % (self.endpoint, url)) - LOG.debug(strutils.safe_encode(' '.join(curl))) + LOG.debug(strutils.safe_encode(' '.join(curl), errors='ignore')) @staticmethod def log_http_response(resp, body=None): diff --git a/tests/test_http.py b/tests/test_http.py index 9310812d..8dabdba7 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -337,6 +337,16 @@ class TestClient(testtools.TestCase): 'timeout': 600.0} self.assertEqual(expected, actual) + def test_log_curl_request_with_non_ascii_char(self): + try: + headers = {'header1': 'value1\xa5\xa6'} + http_client_object = http.HTTPClient(self.endpoint) + http_client_object.log_curl_request('GET', + 'http://www.example.com/\xa5', + {'headers': headers}) + except UnicodeDecodeError as e: + self.fail("Unexpected UnicodeDecodeError exception '%s'" % e) + class TestHostResolutionError(testtools.TestCase):