Python googleapiclient.errors() Examples

The following are 5 code examples for showing how to use googleapiclient.errors(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module googleapiclient , or try the search function .

Example 1
Project: dsub   Author: DataBiosphere   File: google_base.py    License: Apache License 2.0 6 votes vote down vote up
def retry_auth_check(exception, verbose):
  """Specific check for auth error codes.

  Return True if we should retry.

  False otherwise.
  Args:
    exception: An exception to test for transience.
    verbose: If true, output retry messages

  Returns:
    True if we should retry. False otherwise.
  """
  if isinstance(exception, googleapiclient.errors.HttpError):
    if exception.resp.status in HTTP_AUTH_ERROR_CODES:
      _print_retry_error(exception, verbose)
      return True

  return False 
Example 2
Project: streamalert   Author: airbnb   File: gsuite.py    License: Apache License 2.0 6 votes vote down vote up
def _load_credentials(cls, keydata):
        """Load ServiceAccountCredentials from Google service account JSON keyfile

        Args:
            keydata (dict): The loaded keyfile data from a Google service account
                JSON file

        Returns:
             google.oauth2.service_account.ServiceAccountCredentials: Instance of
                service account credentials for this discovery service
        """
        try:
            creds = service_account.Credentials.from_service_account_info(
                keydata,
                scopes=cls._SCOPES,
            )
        except (ValueError, KeyError):
            # This has the potential to raise errors. See: https://tinyurl.com/y8q5e9rm
            LOGGER.exception('[%s] Could not generate credentials from keyfile', cls.type())
            return False

        return creds 
Example 3
Project: listenbrainz-server   Author: metabrainz   File: __init__.py    License: GNU General Public License v2.0 6 votes vote down vote up
def wait_for_completion(projectId, jobId):
    """ Make requests periodically until the passed job has been completed """

    while True:

        try:
            job = bigquery.jobs().get(projectId=projectId, jobId=jobId).execute(num_retries=5)
        except googleapiclient.errors.HttpError as err:
            current_app.logger.error("HttpError while waiting for completion of job: {}".format(err), exc_info=True)
            time.sleep(JOB_COMPLETION_CHECK_DELAY)
            continue

        if job["status"]["state"] == "DONE":
            return
        else:
            time.sleep(JOB_COMPLETION_CHECK_DELAY) 
Example 4
Project: streamalert   Author: airbnb   File: gsuite.py    License: Apache License 2.0 5 votes vote down vote up
def _create_service(self):
        """GSuite requests must be signed with the keyfile

        Returns:
            bool: True if the Google API discovery service was successfully established or False
                if any errors occurred during the creation of the Google discovery service,
        """
        LOGGER.debug('[%s] Creating activities service', self)

        if self._activities_service:
            LOGGER.debug('[%s] Service already instantiated', self)
            return True

        creds = self._load_credentials(self._config.auth['keyfile'])
        if not creds:
            return False

        delegation = creds.with_subject(self._config.auth['delegation_email'])
        try:
            resource = googleapiclient.discovery.build(
                'admin',
                'reports_v1',
                credentials=delegation
            )
        except self._GOOGLE_API_EXCEPTIONS:
            LOGGER.exception('[%s] Failed to build discovery service', self)
            return False

        # The google discovery service 'Resource' class that is returned by
        # 'discovery.build' dynamically loads methods/attributes, so pylint will complain
        # about no 'activities' member existing without the below pylint comment
        self._activities_service = resource.activities()  # pylint: disable=no-member

        return True 
Example 5
Project: dsub   Author: DataBiosphere   File: google_base.py    License: Apache License 2.0 4 votes vote down vote up
def retry_api_check(exception, verbose):
  """Return True if we should retry. False otherwise.

  Args:
    exception: An exception to test for transience.
    verbose: If true, output retry messages

  Returns:
    True if we should retry. False otherwise.
  """
  if isinstance(exception, googleapiclient.errors.HttpError):
    if exception.resp.status in TRANSIENT_HTTP_ERROR_CODES:
      _print_retry_error(exception, verbose)
      return True

  if isinstance(exception, socket.error):
    if exception.errno in TRANSIENT_SOCKET_ERROR_CODES:
      _print_retry_error(exception, verbose)
      return True

  if isinstance(exception, google.auth.exceptions.RefreshError):
    _print_retry_error(exception, verbose)
    return True

  # For a given installation, this could be a permanent error, but has only
  # been observed as transient.
  if isinstance(exception, ssl.SSLError):
    _print_retry_error(exception, verbose)
    return True

  # This has been observed as a transient error:
  #   ServerNotFoundError: Unable to find the server at genomics.googleapis.com
  if isinstance(exception, ServerNotFoundError):
    _print_retry_error(exception, verbose)
    return True

  # Observed to be thrown transiently from auth libraries which use httplib2
  # Use the one from six because httlib no longer exists in Python3
  # https://docs.python.org/2/library/httplib.html
  if isinstance(exception, six.moves.http_client.ResponseNotReady):
    _print_retry_error(exception, verbose)
    return True

  return False