2017-01-17 2 views
0

GCP APIが最初に呼び出されるのは、必ずしもそうではありません。以下はスタックトレースです。GCP観測APIがハングする

Iは、GCPのSDK 1.5.5

シーケンス、のpython 2.7に基づいています:GCPに

http = httplib2.Http() 
credentials = GoogleCredentials.get_application_default() 
    if http: 
     gcp = GCP_discovery.build('compute', 'v1', credentials=credentials, httt 
p=http) 
    else: 
     gcp = GCP_discovery.build('compute', 'v1', credentials=credentials) 
    list = gcp.routes().list(project = project).execute(http=http) 

最後の呼び出しが返されません。 gcp.routes().list()を別のAPIに置き換えるとハングアップも発生します。私がすべてを再始動すれば、うまくいく。私はコード内の問題のカップルを見

File: "/opt/avi/python/bin/cloud_connector/baremetal/gcp_client.py", line 677, in _reconcile_all_vips 
    rtlist = gcp.routes().list(project=xpn_project).execute(http=http) 
File: "/usr/local/lib/python2.7/dist-packages/oauth2client/_helpers.py", line 133, in positional_wrapper 
    return wrapped(*args, **kwargs) 
File: "/usr/local/lib/python2.7/dist-packages/googleapiclient/http.py", line 833, in execute 
    method=str(self.method), body=self.body, headers=self.headers) 
File: "/usr/local/lib/python2.7/dist-packages/googleapiclient/http.py", line 160, in _retry_request 
    resp, content = http.request(uri, method, *args, **kwargs) 
File: "/usr/local/lib/python2.7/dist-packages/oauth2client/transport.py", line 175, in new_request 
    redirections, connection_type) 
File: "/usr/local/lib/python2.7/dist-packages/oauth2client/transport.py", line 282, in request 
    connection_type=connection_type) 
File: "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1609, in request 
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey) 
File: "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1351, in _request 
    (response, content) = self._conn_request(conn, request_uri, method, body, headers) 
File: "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1334, in _conn_request 
    content = response.read() 
File: "/usr/lib/python2.7/httplib.py", line 578, in read 
    return self._read_chunked(amt) 
File: "/usr/lib/python2.7/httplib.py", line 620, in _read_chunked 
    line = self.fp.readline(_MAXLINE + 1) 
File: "/usr/lib/python2.7/socket.py", line 476, in readline 
    data = self._sock.recv(self._rbufsize) 
File: "/usr/lib/python2.7/ssl.py", line 341, in recv 
    return self.read(buflen) 
File: "/usr/lib/python2.7/ssl.py", line 260, in read 
    return self._sslobj.read(len) 
+0

サイトを最大限に活用するには、良い質問をすることが重要です。質問をするためのガイドはhttp://stackoverflow.com/help/how-to-askにあります。 –

答えて

0

あなたが投稿スニペット:

  1. をあなたが(httplib2.Httpを使用して)HTTP2を使用する場合は、authorize the http2 instance to use your GCP account credentialsなければならない代わりにhtttp=http
  2. のタイプミスhttp=httpを持っています。この部分はコードにありません。
  3. 引数をdisccovery.build()に渡す場合は、もう一度credentials=引数を渡すべきではありません(上記のポイント2に関連しています)。 2つの引数は互いに排他的です。
  4. http=引数を​​に渡す必要があるのは、HTTP2を使用している場合のみです。

if条件のため、HTTP2と一緒に使用するのかどうかは分かりません。また、私が上記の問題のどれも、あなたが観察している問題に直接関係しているようには見えないので、あなたの問題を解決することは確実ではありません。

ちょうど参考のために、私はlist() APIをroutesに1000回、HTTP2を一度、HTTPでもう一度呼び出す私のGCPプロジェクトで以下のコードスニペットを試しました。私は私のケースでは何も気づかなかった:

#!/usr/bin/env python 

from googleapiclient.discovery import build 
from oauth2client.client import GoogleCredentials 
import httplib2 

# Fill in your project name here 
PROJECT_NAME = '' 

class GcpComputeApi: 
    def __init__(self, use_http2=False): 
     credentials = GoogleCredentials.get_application_default() 
     self.use_http2 = use_http2 
     if use_http2: 
      self.http = credentials.authorize(httplib2.Http()) 
      self.gcp_compute = build('compute', 'v1', http=self.http) 
     else: 
      self.gcp_compute = build('compute', 'v1', credentials=credentials) 

    def list_routes(self): 
     if self.use_http2: 
      return self.gcp_compute.routes().list(project = PROJECT_NAME).execute(http=self.http) 
     else: 
      return self.gcp_compute.routes().list(project = PROJECT_NAME).execute() 

compute_api = GcpComputeApi() 
for ix in range(1000): 
    list = compute_api.list_routes() 
    print "ix = " + str(ix) + " len = " + str(len(list)) 

compute_api_using_http2 = GcpComputeApi(use_http2=True) 
for ix in range(1000): 
    list = compute_api_using_http2.list_routes() 
    print "ix = " + str(ix) + " len = " + str(len(list))