Skip to content

Commit 205ae59

Browse files
authored
docs: add httplib2 authorization to thread_safety (#1005)
Closes #808 Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/google-api-python-client/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) Fixes #808 🦕
1 parent b94e360 commit 205ae59

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

docs/thread_safety.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ The google-api-python-client library is built on top of the [httplib2](https://g
99
The easiest way to provide threads with their own `httplib2.Http()` instances is to either override the construction of it within the service object or to pass an instance via the http argument to method calls.
1010

1111
```python
12+
import google.auth
13+
import googleapiclient
14+
import google_auth_httplib2
15+
import httplib2
16+
from googleapiclient import discovery
17+
1218
# Create a new Http() object for every request
1319
def build_request(http, *args, **kwargs):
14-
new_http = httplib2.Http()
15-
return apiclient.http.HttpRequest(new_http, *args, **kwargs)
16-
service = build('api_name', 'api_version', requestBuilder=build_request)
20+
new_htpp = google_auth_httplib2.AuthorizedHttp(credentials, http=httplib2.Http())
21+
return googleapiclient.http.HttpRequest(new_http, *args, **kwargs)
22+
service = discovery.build('api_name', 'api_version', requestBuilder=build_request)
1723

1824
# Pass in a new Http() manually for every request
19-
service = build('api_name', 'api_version')
20-
http = httplib2.Http()
25+
service = discovery.build('api_name', 'api_version')
26+
http = google_auth_httplib2.AuthorizedHttp(credentials, http=httplib2.Http())
2127
service.stamps().list().execute(http=http)
22-
```
28+
```

0 commit comments

Comments
 (0)