diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index 8c7937a..91193db 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -130,7 +130,8 @@ class HTTPClient(object): if body: body = strutils.safe_decode(body) dump.extend([body, '']) - LOG.debug('\n'.join([strutils.safe_encode(x) for x in dump])) + LOG.debug('\n'.join([strutils.safe_encode(x, errors='ignore') + for x in dump])) @staticmethod def encode_headers(headers): diff --git a/tests/test_http.py b/tests/test_http.py index 0c8a4ac..89bc2af 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -232,6 +232,16 @@ class TestClient(testtools.TestCase): self.assertTrue(isinstance(body, types.GeneratorType)) self.assertEqual([data], list(body)) + def test_log_http_response_with_non_ascii_char(self): + try: + response = 'Ok' + headers = {"Content-Type": "text/plain", + "test": "value1\xa5\xa6"} + fake = utils.FakeResponse(headers, six.StringIO(response)) + self.client.log_http_response(fake) + except UnicodeDecodeError as e: + self.fail("Unexpected UnicodeDecodeError exception '%s'" % e) + class TestVerifiedHTTPSConnection(testtools.TestCase): """Test fixture for glanceclient.common.http.VerifiedHTTPSConnection."""