Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
Specify HTTP client when constructing client (#1275)
Browse files Browse the repository at this point in the history
If a HTTP client is not passed to `build`, the Google API Python client
will create a default one and attempt to authenticate it. This causes
failures in environments where ADC auth is not available (Travis).

In any case, it's not useful to access any auth code in the mock tests.
This commit removes that possibility.
  • Loading branch information
saicheems authored May 18, 2017
1 parent 2c2323e commit daa59cd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private SampleView createSampleView(SampleTransformerContext context) {
discoveryBuildParams.add(String.format("'%s'", config.apiVersion()));
switch (config.authType()) {
case NONE:
discoveryBuildParams.add("http=httplib2.Http(timeout=60)");
break;
case API_KEY:
discoveryBuildParams.add("developerKey=" + credentialsVarName);
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/com/google/api/codegen/py/sample.snip
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
from pprint import pprint
@end

@if class.auth.type == "NONE"
import httplib2
@end
from googleapiclient import discovery
@if class.auth.type == "APPLICATION_DEFAULT_CREDENTIALS"
from oauth2client.client import GoogleCredentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ BEFORE RUNNING:
"""
from pprint import pprint

import httplib2
from googleapiclient import discovery

service = discovery.build('foo', 'v1', discoveryServiceUrl='localhost:8080/$discovery/foo?version=v1')
service = discovery.build('foo', 'v1', http=httplib2.Http(timeout=60), discoveryServiceUrl='localhost:8080/$discovery/foo?version=v1')

request = service.baz().get()
response = request.execute()
Expand Down

0 comments on commit daa59cd

Please sign in to comment.