Python GCE API: oauth2client.util: execute () accepts no more than 1 positional argument (2 data)

I am trying to start with the Python API for the Google Compute Engine using the hello world tutorial at https://developers.google.com/compute/docs/api/python_guide#setup

When making a call, response = request.execute(auth_http) , although I get the following error signaling, which I cannot authenticate:

 WARNING:oauth2client.util:execute() takes at most 1 positional argument (2 given) 

I obviously only pass one positional argument (auth_http) and I searched for the answers oauth2client / util.py, apiclient / http.py and oauth2client / client.py, but nothing seems to be wrong. I found a stack overflow message that ran into the same problem, but it looks like in the constructor of the OAuth2WebServerFlow class in oauth2client / client.py, the access_type parameter is set to 'offline' already (although, to be honest, I do not quite understand what is happening here in terms of configuring oauth2.0 streams).

Any suggestions would be greatly appreciated, and thanks in advance!

+6
source share
3 answers

Looking at the code, the annotation @ util.positional (1) throws a warning. Avoid using named parameters.

Instead:

 response = request.execute(auth_http) 

make:

 response = request.execute(http=auth_http) 

https://code.google.com/p/google-api-python-client/source/browse/apiclient/http.py#637

+7
source

I think the documentation is incorrect. Please use the following:

 auth_http = credentials.authorize(http) # Build the service gce_service = build('compute', API_VERSION, http=auth_http) project_url = '%s%s' % (GCE_URL, PROJECT_ID) # List instances request = gce_service.instances().list(project=PROJECT_ID, filter=None, zone=DEFAULT_ZONE) response = request.execute() 
+5
source

Here you can do one of three things:

1 Ignore warnings and do nothing.

2 Suppress warnings and set the flag to ignore:

 import oauth2client import gflags gflags.FLAGS['positional_parameters_enforcement'].value = 'IGNORE' 

3 See where the positional parameter is and correct it:

 import oauth2client import gflags gflags.FLAGS['positional_parameters_enforcement'].value = 'EXCEPTION' # Implement a try and catch around your code: try: pass except TypeError, e: # Print the stack so you can fix the problem, see python exception traceback docs. print str(e) 
+1
source

All Articles