3

我正在尝试使用 'returnImmediately' = False 设置用户定义的消息拉取超时:

    PUBSUB_SCOPES = ['https://www.googleapis.com/auth/pubsub']

    credentials = oauth2client.GoogleCredentials.get_application_default()
    if credentials.create_scoped_required():
        credentials = credentials.create_scoped(PUBSUB_SCOPES)

    http = httplib2.Http(timeout=timeout)
    credentials.authorize(http)

    return discovery.build('pubsub', 'v1', http=http)

当超时 < 90 秒时,我收到以下错误:

resp = client.projects().subscriptions().pull(subscription=subscription, body=body).execute()
  File "venv\lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "venv\lib\site-packages\googleapiclient\http.py", line 755, in execute
    method=str(self.method), body=self.body, headers=self.headers)
  File "venv\lib\site-packages\googleapiclient\http.py", line 93, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "venv\lib\site-packages\oauth2client\client.py", line 622, in new_request
    redirections, connection_type)
  File "venv\lib\site-packages\httplib2\__init__.py", line 1609, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "venv\lib\site-packages\httplib2\__init__.py", line 1351, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "venv\lib\site-packages\httplib2\__init__.py", line 1307, in _conn_request
    response = conn.getresponse()
  File "C:\python27\Lib\httplib.py", line 1074, in getresponse
    response.begin()
  File "C:\python27\Lib\httplib.py", line 415, in begin
    version, status, reason = self._read_status()
  File "C:\python27\Lib\httplib.py", line 371, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "C:\python27\Lib\socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
  File "C:\python27\Lib\ssl.py", line 714, in recv
    return self.read(buflen)
  File "C:\python27\Lib\ssl.py", line 608, in read
    v = self._sslobj.read(len or 1024)
SSLError: ('The read operation timed out',)

谢谢。

4

1 回答 1

3

不幸的是,这些客户端库不支持将超时值转发到服务器;但是,我们刚刚发布了 gRPC 客户端库,它们正确地将最后期限传递给了服务器。

正如您的问题所暗示的,作为当前库的解决方法,要么使用 returnImmediately=true,要么设置高于 90 秒的截止日期。

于 2016-03-23T03:45:04.963 回答