Oauth 2.0 GCE Python API:oauth2client.util:execute()最多接受1个位置参数(给定2个)
我正在尝试使用他们的“hello world”教程开始使用用于Google计算引擎的Python API 无论何时调用Oauth 2.0 GCE Python API:oauth2client.util:execute()最多接受1个位置参数(给定2个),oauth-2.0,google-compute-engine,Oauth 2.0,Google Compute Engine,我正在尝试使用他们的“hello world”教程开始使用用于Google计算引擎的Python API 无论何时调用response=request.execute(auth_http),我都会收到以下错误信号,表明我无法进行身份验证: WARNING:oauth2client.util:execute() takes at most 1 positional argument (2 given) 很明显,我只传递了一个位置参数(auth_http),我已经查看了oauth2client/u
response=request.execute(auth_http)
,我都会收到以下错误信号,表明我无法进行身份验证:
WARNING:oauth2client.util:execute() takes at most 1 positional argument (2 given)
很明显,我只传递了一个位置参数(auth_http),我已经查看了oauth2client/util.py、apiclient/http.py和oauth2client/client.py以获得答案,但似乎没有任何问题。我发现它遇到了同样的问题,但似乎在oauth2client/client.py中的OAuth2WebServerFlow类的构造函数中,“access_type”已经设置为“offline”(尽管老实说,我不完全理解在设置oauth2.0流方面发生了什么)
如有任何建议,将不胜感激,并提前感谢 我认为文档是错误的。请使用以下各项:
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()
查看代码,@util.positional(1)注释抛出了警告。避免使用命名参数 而不是:
response = request.execute(auth_http)
做:
您可以在此处执行以下三项操作之一: 1忽略警告,什么也不做 2抑制警告并将标志设置为忽略:
import oauth2client
import gflags
gflags.FLAGS['positional_parameters_enforcement'].value = 'IGNORE'
3找出提供位置参数的位置并修复它:
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)
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)