diff --git a/heatclient/common/http.py b/heatclient/common/http.py index 576e3642..16d1bf62 100644 --- a/heatclient/common/http.py +++ b/heatclient/common/http.py @@ -160,7 +160,7 @@ class HTTPClient(object): self.log_http_response(resp, body_str) if 400 <= resp.status < 600: - raise exc.from_response(resp, body_iter) + raise exc.from_response(resp, body_str) elif resp.status in (301, 302, 305): # Redirected. Reissue the request to the new location. location = resp.getheader('location', None) @@ -175,7 +175,7 @@ class HTTPClient(object): raise exc.InvalidEndpoint(message=message) return self._http_request(location, method, **kwargs) elif resp.status == 300: - raise exc.from_response(resp, body_iter) + raise exc.from_response(resp, body_str) return resp, body_str @@ -187,10 +187,10 @@ class HTTPClient(object): if 'body' in kwargs: kwargs['body'] = json.dumps(kwargs['body']) - resp, body_iter = self._http_request(url, method, **kwargs) + resp, body_str = self._http_request(url, method, **kwargs) if 'application/json' in resp.getheader('content-type', None): - body = ''.join([chunk for chunk in body_iter]) + body = body_str try: body = json.loads(body) except ValueError: diff --git a/tests/test_common_http.py b/tests/test_common_http.py index e32ce0ef..eb105906 100644 --- a/tests/test_common_http.py +++ b/tests/test_common_http.py @@ -183,7 +183,14 @@ class HttpClientTest(unittest.TestCase): # Replay, create client, assert self.m.ReplayAll() client = http.HTTPClient('http://example.com:8004') - self.assertRaises(exc.HTTPNotFound, client.json_request, 'GET', '') + try: + client.json_request('GET', '') + self.fail('No exception raised') + except exc.HTTPNotFound as e: + # Assert that the raised exception can be converted to string + self.assertNotEqual(e.message, None) + except: + raise self.m.VerifyAll() def test_http_300_json_request(self): @@ -200,7 +207,14 @@ class HttpClientTest(unittest.TestCase): # Replay, create client, assert self.m.ReplayAll() client = http.HTTPClient('http://example.com:8004') - self.assertRaises(exc.HTTPMultipleChoices, client.json_request, 'GET', '') + try: + client.json_request('GET', '') + self.fail('No exception raised') + except exc.HTTPMultipleChoices as e: + # Assert that the raised exception can be converted to string + self.assertNotEqual(e.message, None) + except: + raise self.m.VerifyAll() #def test_https_json_request(self):