From d1384e661b95182e196a07293a061697b7f72f44 Mon Sep 17 00:00:00 2001 From: Ana Krivokapic Date: Thu, 26 Jun 2014 14:48:30 +0200 Subject: [PATCH] Pass the requests.Response object to from_response() from_response() method expects a requests.Response object, so we need to convert the existing httplib.HTTPResponse instance to requests.Response. Change-Id: I15da7fcea7e90972da7508feea470a16ce2a4f12 Closes-bug: #1313731 --- tuskarclient/common/http.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tuskarclient/common/http.py b/tuskarclient/common/http.py index c6646d1..2f13d38 100644 --- a/tuskarclient/common/http.py +++ b/tuskarclient/common/http.py @@ -18,6 +18,8 @@ import logging import os import socket +import requests + from six.moves import http_client as httplib from six.moves.urllib import parse as urlparse from six import StringIO @@ -169,10 +171,14 @@ class HTTPClient(object): if 400 <= resp.status < 600: LOG.warn("Request returned failure status.") - # NOTE(viktors): from_response() method checks for `status_code` - # attribute, instead of `status`, so we should add it to response - resp.status_code = resp.status - raise exc.from_response(resp, method, conn_url) + # NOTE(akrivoka): from_response() method expects a + # requests.Response object so we have to convert from + # httplib.HTTPResponse + response = requests.Response() + response.status_code = resp.status + response.headers.update(resp.getheaders()) + response._content = resp.read() + raise exc.from_response(response, method, conn_url) elif resp.status in (301, 302, 305): # Redirected. Reissue the request to the new location. new_location = resp.getheader('location')