Search code examples
pythonpython-2.7sslhttplib2google-cloud-pubsub

Pull timeout with google-api-python-client


I am trying to set a user defined timeout on message pull with '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)

When the timeout is < 90 seconds I get the following errors:

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',)

Thanks.


Solution

  • Unfortunately these client libraries do not support forwarding the timeout values to the server; however, we have just announced the gRPC client libraries, which correctly pass the deadline to the server.

    As a workaround for the current libraries, either use returnImmediately=true, or set a deadline higher than 90 seconds, as your question implies.