Repository: libcloud Updated Branches: refs/heads/trunk 27ca9167c -> 23f400ed6
Fix improper getresponse() uses Closes #1133 During the migration from httplib to requests, a lot of driver code did not change because they use the high-level libcloud API which hid the change from httplib to requests with the HttpLibResponseProxy adapter. However, in some cases, driver code needs to access the actual response, and does this by calling getresponse(). While this used to return an httlib.HTTPResponse instance, this now returns a requests.Response instance. All code covered by tests was fixed, but OVH and Brightbox common code is not fully covered. I don't have a subscription to either service and can't test the change, but the resulting code can only be more correct since it fixes the `getresponse() result comes from httplib` assumption. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/23f400ed Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/23f400ed Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/23f400ed Branch: refs/heads/trunk Commit: 23f400ed6d7902284ba316730c7550c0c76937e1 Parents: 27ca916 Author: Quentin Pradet <[email protected]> Authored: Mon Oct 16 14:11:50 2017 +0400 Committer: Quentin Pradet <[email protected]> Committed: Mon Jan 8 16:32:03 2018 +0400 ---------------------------------------------------------------------- libcloud/common/brightbox.py | 5 ++--- libcloud/common/ovh.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/23f400ed/libcloud/common/brightbox.py ---------------------------------------------------------------------- diff --git a/libcloud/common/brightbox.py b/libcloud/common/brightbox.py index 1943dda..77270c0 100644 --- a/libcloud/common/brightbox.py +++ b/libcloud/common/brightbox.py @@ -78,12 +78,11 @@ class BrightboxConnection(ConnectionUserAndKey): response = self.connection.request(method='POST', url='/token', body=body, headers=headers) - response = self.connection.getresponse() - if response.status == httplib.OK: return json.loads(response.read())['access_token'] else: - responseCls = BrightboxResponse(response=response, connection=self) + responseCls = BrightboxResponse( + response=response.getresponse(), connection=self) message = responseCls.parse_error() raise InvalidCredsError(message) http://git-wip-us.apache.org/repos/asf/libcloud/blob/23f400ed/libcloud/common/ovh.py ---------------------------------------------------------------------- diff --git a/libcloud/common/ovh.py b/libcloud/common/ovh.py index 260ea41..733ab07 100644 --- a/libcloud/common/ovh.py +++ b/libcloud/common/ovh.py @@ -104,13 +104,12 @@ class OvhConnection(ConnectionUserAndKey): } httpcon = LibcloudConnection(host=self.host, port=443) httpcon.request(method='POST', url=action, body=data, headers=headers) - response = httpcon.getresponse() + response = JsonResponse(httpcon.getresponse(), httpcon) if response.status == httplib.UNAUTHORIZED: raise InvalidCredsError() - body = response.read() - json_response = json.loads(body) + json_response = response.parse_body() httpcon.close() return json_response
