Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCE Python API: oauth2client.util:execute() takes at most 1 positional argument (2 given)

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!

like image 894
sova Avatar asked Apr 14 '13 17:04

sova


2 Answers

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

like image 122
Felipe Hoffa Avatar answered Sep 27 '22 16:09

Felipe Hoffa


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()
like image 31
Burcu Dogan Avatar answered Sep 27 '22 17:09

Burcu Dogan