當前位置: 首頁>>代碼示例>>Python>>正文


Python googleapiclient.errors方法代碼示例

本文整理匯總了Python中googleapiclient.errors方法的典型用法代碼示例。如果您正苦於以下問題:Python googleapiclient.errors方法的具體用法?Python googleapiclient.errors怎麽用?Python googleapiclient.errors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在googleapiclient的用法示例。


在下文中一共展示了googleapiclient.errors方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: retry_auth_check

# 需要導入模塊: import googleapiclient [as 別名]
# 或者: from googleapiclient import errors [as 別名]
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 
開發者ID:DataBiosphere,項目名稱:dsub,代碼行數:21,代碼來源:google_base.py

示例2: _load_credentials

# 需要導入模塊: import googleapiclient [as 別名]
# 或者: from googleapiclient import errors [as 別名]
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 
開發者ID:airbnb,項目名稱:streamalert,代碼行數:24,代碼來源:gsuite.py

示例3: wait_for_completion

# 需要導入模塊: import googleapiclient [as 別名]
# 或者: from googleapiclient import errors [as 別名]
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) 
開發者ID:metabrainz,項目名稱:listenbrainz-server,代碼行數:18,代碼來源:__init__.py

示例4: _create_service

# 需要導入模塊: import googleapiclient [as 別名]
# 或者: from googleapiclient import errors [as 別名]
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 
開發者ID:airbnb,項目名稱:streamalert,代碼行數:36,代碼來源:gsuite.py

示例5: retry_api_check

# 需要導入模塊: import googleapiclient [as 別名]
# 或者: from googleapiclient import errors [as 別名]
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 
開發者ID:DataBiosphere,項目名稱:dsub,代碼行數:46,代碼來源:google_base.py


注:本文中的googleapiclient.errors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。