首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GCP -观测API挂

GCP -观测API挂
EN

Stack Overflow用户
提问于 2017-01-17 03:03:51
回答 1查看 335关注 0票数 0

我看到对GCP的第一个调用有时挂起--并不总是这样。下面是堆栈跟踪。

我基于python2.7,GCP 1.5.5

序列:

代码语言:javascript
复制
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的最后一次调用永远不会返回。用不同的API替换gcp.routes().list()也会导致挂起。如果我重新开始一切都很顺利。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2017-05-08 02:23:02

我在您发布的代码片段中看到了几个问题:

  1. 您有一个错误http=http而不是htttp=http
  2. 如果您想使用HTTP2 (使用httplib2.Http),您应该使用授权http2实例使用GCP帐户凭据。这个部分在你的代码中丢失了。
  3. 如果要将http=参数传递给disccovery.build(),则不应该再传递credentials=参数(与上文第2点相关)。这两个论点是相互排斥的。
  4. 只有在使用http=时,才需要将HTTP2参数传递给HTTP2。

由于if条件,不太清楚您是否打算与HTTP2一起使用。而且,上面提到的问题似乎都与您所观察到的问题没有直接关系,所以不能完全确定它是否会解决您的问题。

仅供参考,我在我的GCP项目上尝试了下面的代码片段,它在routes上调用routes API 1000次,不使用HTTP2,然后再次使用HTTP2。我没有注意到在我的案件中有什么悬念:

代码语言:javascript
复制
#!/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))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41688437

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档