7

I'm trying to get started with the Python API for Google Compute Engine using their "hello world" tutorial on https://developers.google.com/compute/docs/api/python_guide#setup

Whenever making the call response = request.execute(auth_http) though, I get the following error signaling that I can't authenticate:

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

I'm clearly only passing one positional argument (auth_http), and I've looked into oauth2client/util.py, apiclient/http.py, and oauth2client/client.py for answers, but nothing seems amiss. I found another stack overflow post that encountered the same issue, but it seems that in the constructor of the OAuth2WebServerFlow class in oauth2client/client.py, 'access_type' is set to 'offline' already (though to be honest I don't completely understand what's going on here in terms of setting up oauth2.0 flows).

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

Community
  • 1
  • 1
sova
  • 101
  • 5

3 Answers3

9

Looking at the code, the @util.positional(1) annotation is throwing the warning. Avoid it using named parameters.

Instead of:

response = request.execute(auth_http)

Do:

response = request.execute(http=auth_http)

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

Felipe Hoffa
  • 54,922
  • 16
  • 151
  • 325
5

I think documentation is wrong. 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()
Burcu Dogan
  • 9,153
  • 4
  • 34
  • 34
2

You can do one of three things here:

1 Ignore the warnings and do nothing.

2 Suppress the warnings and set the flag to ignore:

import oauth2client
import gflags

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

3 Figure out where the positional parameter is being provided and fix 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)
Craig
  • 4,268
  • 4
  • 36
  • 53