使用google-api-python-client拉取超时

时间:2016-03-21 19:47:11

标签: python python-2.7 ssl httplib2 google-cloud-pubsub

我正在尝试使用'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)

超时时间<&lt; 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',)

感谢。

1 个答案:

答案 0 :(得分:2)

不幸的是,这些客户端库不支持将超时值转发到服务器;但是,我们有just announced the gRPC client libraries,它正确地将截止日期传递给服务器。

作为当前库的变通方法,要么使用returnImmediately = true,要么设置一个高于90秒的截止时间,正如您的问题所暗示的那样。