Skip to content

Commit 496af68

Browse files
author
Jon Wayne Parrott
committed
Datastore: replace httplib2 with Requests
1 parent 27bb81e commit 496af68

File tree

3 files changed

+132
-141
lines changed

3 files changed

+132
-141
lines changed

datastore/google/cloud/datastore/_http.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
def _request(http, project, method, data, base_url):
4040
"""Make a request over the Http transport to the Cloud Datastore API.
4141
42-
:type http: :class:`~httplib2.Http`
42+
:type http: :class:`requests.Session`
4343
:param http: HTTP object to make requests.
4444
4545
:type project: str
@@ -63,27 +63,26 @@ def _request(http, project, method, data, base_url):
6363
"""
6464
headers = {
6565
'Content-Type': 'application/x-protobuf',
66-
'Content-Length': str(len(data)),
6766
'User-Agent': connection_module.DEFAULT_USER_AGENT,
6867
connection_module.CLIENT_INFO_HEADER: _CLIENT_INFO,
6968
}
7069
api_url = build_api_url(project, method, base_url)
71-
headers, content = http.request(
72-
uri=api_url, method='POST', headers=headers, body=data)
7370

74-
status = headers['status']
75-
if status != '200':
76-
error_status = status_pb2.Status.FromString(content)
77-
raise exceptions.make_exception(
78-
headers, error_status.message, use_json=False)
71+
response = http.request(
72+
url=api_url, method='POST', headers=headers, data=data)
7973

80-
return content
74+
if response.status_code != 200:
75+
error_status = status_pb2.Status.FromString(response.content)
76+
raise exceptions.from_http_status(
77+
response.status_code, error_status.message, errors=[error_status])
78+
79+
return response.content
8180

8281

8382
def _rpc(http, project, method, base_url, request_pb, response_pb_cls):
8483
"""Make a protobuf RPC request.
8584
86-
:type http: :class:`~httplib2.Http`
85+
:type http: :class:`requests.Session`
8786
:param http: HTTP object to make requests.
8887
8988
:type project: str

datastore/google/cloud/datastore/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ class Client(ClientWithProject):
177177
passed), falls back to the default inferred from the
178178
environment.
179179
180-
:type _http: :class:`~httplib2.Http`
180+
:type _http: :class:`~requests.Session`
181181
:param _http: (Optional) HTTP object to make requests. Can be any object
182182
that defines ``request()`` with the same interface as
183-
:meth:`~httplib2.Http.request`. If not passed, an
183+
:meth:`requests.Session.request`. If not passed, an
184184
``_http`` object is created that is bound to the
185185
``credentials`` for the current object.
186186
This parameter should be considered private, and could

0 commit comments

Comments
 (0)