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
This commit is contained in:
parent
222272850a
commit
d1384e661b
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue