GCE Python API:oauth2client.util:execute()最多需要1个位置参数(给定2个)

sov*_*ova 6 oauth-2.0 google-compute-engine

我正在尝试使用https://developers.google.com/compute/docs/api/python_guide#setup上的"hello world"教程开始使用Google Compute Engine的Python API.

无论何时拨打电话response = request.execute(auth_http),我都会收到以下错误信号:我无法进行身份验证:

WARNING:oauth2client.util:execute() takes at most 1 positional argument (2 given)
Run Code Online (Sandbox Code Playgroud)

我显然只传递了一个位置参数(auth_http),我查看了oauth2client/util.py,apiclient/http.py和oauth2client/client.py以获得答案,但似乎没有任何问题.我发现另一个堆栈溢出帖子遇到了同样的问题,但似乎在oauth2client/client.py中的OAuth2WebServerFlow类的构造函数中,'access_type'已经设置为'offline'(虽然说实话我并不完全了解在设置oauth2.0流程方面发生了什么.

任何建议将不胜感激,并提前感谢!

Fel*_*ffa 8

查看代码,@ util.positional(1)注释抛出警告.避免使用命名参数.

代替:

response = request.execute(auth_http)
Run Code Online (Sandbox Code Playgroud)

做:

response = request.execute(http=auth_http)
Run Code Online (Sandbox Code Playgroud)

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


Bur*_*gan 5

我认为文档是错误的.请使用以下内容:

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()
Run Code Online (Sandbox Code Playgroud)