7

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)

私は明らかに 1 つの位置引数 (auth_http) だけを渡しています。回答を得るために oauth2client/util.py、apiclient/http.py、および oauth2client/client.py を調べましたが、問題はないようです。同じ問題が発生した別のスタック オーバーフローの投稿を見つけましたが、oauth2client/client.py の OAuth2WebServerFlow クラスのコンストラクターで、'access_type' が既に 'offline' に設定されているようです (正直なところ、完全にはわかりませんが)。 oauth2.0 フローの設定に関してここで何が起こっているかを理解してください)。

どんな提案でも大歓迎です。事前に感謝します!

4

3 に答える 3

9

コードを見ると、 @util.positional(1) アノテーションが警告をスローしています。名前付きパラメーターの使用は避けてください。

それ以外の:

response = request.execute(auth_http)

行う:

response = request.execute(http=auth_http)

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

于 2013-05-20T05:38:01.583 に答える
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()
于 2013-04-17T13:22:12.027 に答える
2

ここでは、次の 3 つのいずれかを実行できます。

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)
于 2013-09-23T20:40:55.843 に答える