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


Python httplib2.HttpLib2Error方法代碼示例

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


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

示例1: _execute_insert_request

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def _execute_insert_request(self, request):
    """Executes a table/dataset insert request, retrying on transport errors."""
    for i in range(NUM_RETRIES + 1):
      try:
        request.execute()
        return True
      except HttpError as e:
        if e.resp.status == 409:
          # Already exists.
          return True

        logs.log_error('Failed to insert table/dataset.')
        return False
      except httplib2.HttpLib2Error:
        # Transport error.
        time.sleep(random.uniform(0, (1 << i) * RETRY_SLEEP_TIME))
        continue

    logs.log_error('Failed to insert table/dataset.')
    return False 
開發者ID:google,項目名稱:clusterfuzz,代碼行數:22,代碼來源:load_bigquery_stats.py

示例2: object_put

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def object_put(auth, path, data, mimetype='application/octet-stream'):
  bucket, filename = path.split(':', 1)
  service = get_service('storage', 'v1', auth)

  media = MediaIoBaseUpload(data, mimetype=mimetype, chunksize=CHUNKSIZE, resumable=True)
  request = service.objects().insert(bucket=bucket, name=filename, media_body=media)

  response = None
  errors = 0
  while response is None:
    error = None
    try:
      status, response = request.next_chunk()
      if project.verbose and status: print("Uploaded %d%%." % int(status.progress() * 100))
    except HttpError as e:
      if e.resp.status < 500: raise
      error = e
    except (httplib2.HttpLib2Error, IOError) as e:
      error = e

    errors = (errors + 1) if error else 0
    if errors > RETRIES: raise error

  if project.verbose: print("Uploaded 100%.") 
開發者ID:google,項目名稱:starthinker,代碼行數:26,代碼來源:__init__.py

示例3: _refresh

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def _refresh(self, http_request):
        """Refreshes the access_token.

        Skip all the storage hoops and just refresh using the API.

        Args:
            http_request: callable, a callable that matches the method
                          signature of httplib2.Http.request, used to make
                          the refresh request.

        Raises:
            HttpAccessTokenRefreshError: When the refresh fails.
        """
        try:
            self._retrieve_info(http_request)
            self.access_token, self.token_expiry = _metadata.get_token(
                http_request, service_account=self.service_account_email)
        except httplib2.HttpLib2Error as e:
            raise client.HttpAccessTokenRefreshError(str(e)) 
開發者ID:fniephaus,項目名稱:alfred-gmail,代碼行數:21,代碼來源:gce.py

示例4: request

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def request(self, uri, method='GET', body=None, *args, **kwargs):
    for i in range(1, self._max_tries + 1):
      try:
        response, content = self._http.request(uri, method, body, *args,
                                               **kwargs)

        if self._retrying_statuses_fn(response.status):
          logging.info('RetriableHttp: attempt %d receiving status %d, %s',
                       i, response.status,
                       'final attempt' if i == self._max_tries else \
                       'will retry')
        else:
          break
      except (ValueError, errors.Error,
              socket.timeout, socket.error, socket.herror, socket.gaierror,
              httplib2.HttpLib2Error) as error:
        logging.info('RetriableHttp: attempt %d received exception: %s, %s',
                     i, error, 'final attempt' if i == self._max_tries else \
                     'will retry')
        if i == self._max_tries:
          raise
      time.sleep(self._backoff_time)

    return response, content 
開發者ID:luci,項目名稱:luci-py,代碼行數:26,代碼來源:httplib2_utils.py

示例5: send

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def send(self, metric_pb):
    body = self.encode_to_json(metric_pb)

    try:
      resp, content = self._http.request(self._endpoint,
          method='POST',
          body=body,
          headers={'Content-Type': 'application/json'})
      if resp.status == 200:
        self._failed = False
      else:
        logging.warning('HttpsMonitor.send received status %d: %s', resp.status,
                        content)
        self._failed = True
    except (ValueError, errors.Error,
            socket.timeout, socket.error, socket.herror, socket.gaierror,
            httplib2.HttpLib2Error):
      logging.exception('HttpsMonitor.send failed')
      self._failed = True 
開發者ID:luci,項目名稱:luci-py,代碼行數:21,代碼來源:monitors.py

示例6: get_app

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def get_app(self, project_id):
        """Gets information about an application.

        Args:
            project_id (str): The id of the project.

        Returns:
            dict: The response of retrieving the AppEngine app.
        """
        try:
            results = self.repository.apps.get(project_id)
            LOGGER.debug('Getting information about an application,'
                         ' project_id = %s, result = %s', project_id, results)
            return results
        except (errors.HttpError, HttpLib2Error) as e:
            if _is_status_not_found(e):
                return {}
            raise api_errors.ApiExecutionError(project_id, e) 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:20,代碼來源:appengine.py

示例7: get_service

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def get_service(self, project_id, service_id):
        """Gets information about a specific service.

        Args:
            project_id (str): The id of the project.
            service_id (str): The id of the service to query.

        Returns:
            dict: A Service resource dict for a given project_id and
            service_id.
        """
        try:
            results = self.repository.app_services.get(
                project_id, target=service_id)
            LOGGER.debug('Getting information about a specific service,'
                         ' project_id = %s, service_id = %s, results = %s',
                         project_id, service_id, results)
            return results
        except (errors.HttpError, HttpLib2Error) as e:
            if _is_status_not_found(e):
                return {}
            raise api_errors.ApiExecutionError(project_id, e) 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:24,代碼來源:appengine.py

示例8: list_services

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def list_services(self, project_id):
        """Lists services of a project.

        Args:
            project_id (str): The id of the project.

        Returns:
            list: A list of Service resource dicts for a project_id.
        """
        try:
            paged_results = self.repository.app_services.list(project_id)
            flattened_results = api_helpers.flatten_list_results(
                paged_results, 'services')
            LOGGER.debug('Listing services of a project, project_id = %s,'
                         ' flattened_results = %s',
                         project_id, flattened_results)
            return flattened_results
        except (errors.HttpError, HttpLib2Error) as e:
            if _is_status_not_found(e):
                return []
            raise api_errors.ApiExecutionError(project_id, e) 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:23,代碼來源:appengine.py

示例9: get_version

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def get_version(self, project_id, service_id, version_id):
        """Gets information about a specific version of a service.

        Args:
            project_id (str): The id of the project.
            service_id (str): The id of the service to query.
            version_id (str): The id of the version to query.

        Returns:
            dict: A Version resource dict for a given project_id and
            service_id.
        """
        try:
            results = self.repository.service_versions.get(
                project_id, target=version_id, services_id=service_id)
            LOGGER.debug('Getting information about a specific version'
                         ' of a service, project_id = %s, service_id = %s,'
                         ' version_id = %s, results = %s',
                         project_id, service_id, version_id, results)
            return results
        except (errors.HttpError, HttpLib2Error) as e:
            if _is_status_not_found(e):
                return {}
            raise api_errors.ApiExecutionError(project_id, e) 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:26,代碼來源:appengine.py

示例10: _flatten_list_results

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def _flatten_list_results(project_id, paged_results, item_key):
    """Flatten results and handle exceptions.

    Args:
        project_id (str): The project id the results are for.
        paged_results (list): A list of paged API response objects.
            [{page 1 results}, {page 2 results}, {page 3 results}, ...]
        item_key (str): The name of the key within the inner "items" lists
            containing the objects of interest.

    Returns:
        list: A list of items.

    Raises:
        ApiNotEnabledError: Raised if the API is not enabled for the project.
        ApiExecutionError: Raised if there is another error while calling the
            API method.
    """
    try:
        return api_helpers.flatten_list_results(paged_results, item_key)
    except (errors.HttpError, HttpLib2Error) as e:
        api_not_enabled, details = _api_not_enabled(e)
        if api_not_enabled:
            raise api_errors.ApiNotEnabledError(details, e)
        raise api_errors.ApiExecutionError(project_id, e) 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:27,代碼來源:compute.py

示例11: get_snapshots

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def get_snapshots(self, project_id):
        """Return the list of all snapshots in the project.

        Args:
            project_id (str): The project id.

        Returns:
            list: A list of snapshot resources for this project.
        """

        try:
            LOGGER.debug('Getting the list of all snapshots in project: %s',
                         project_id)
            repository = self.repository.snapshots
            results = repository.list(project_id)
            return api_helpers.flatten_list_results(results, 'items')
        except (errors.HttpError, HttpLib2Error) as e:
            api_not_enabled, details = _api_not_enabled(e)
            if api_not_enabled:
                err = api_errors.ApiNotEnabledError(details, e)
            else:
                err = api_errors.ApiExecutionError(project_id, e)

            LOGGER.warning(err)
            raise err 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:27,代碼來源:compute.py

示例12: get_image

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def get_image(self, project_id, image_name):
        """Get an image from a project.

        Args:
            project_id (str): The project id.
            image_name (str): The image name to get.

        Returns:
            dict: A Compute Image resource dict.
            https://cloud.google.com/compute/docs/reference/latest/images
        """
        try:
            results = self.repository.images.get(project_id, target=image_name)
            LOGGER.debug('Getting an image from a project, project_id = %s, '
                         'image_name = %s, results = %s',
                         project_id, image_name, results)
            return results
        except (errors.HttpError, HttpLib2Error) as e:
            api_not_enabled, details = _api_not_enabled(e)
            if api_not_enabled:
                raise api_errors.ApiNotEnabledError(details, e)
            raise api_errors.ApiExecutionError(project_id, e) 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:24,代碼來源:compute.py

示例13: is_api_enabled

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def is_api_enabled(self, project_id):
        """Checks if the Compute API is enabled for the specified project.

        Args:
            project_id (str): The project id.

        Returns:
            bool: True if the API is enabled, else False.
        """
        try:
            result = self.repository.projects.get(project_id, fields='name')
            LOGGER.debug('Checking if Compute API is enabled, project_id = '
                         '%s, result = %s', project_id, result)
            return bool('name' in result)  # True if name, otherwise False.
        except (errors.HttpError, HttpLib2Error) as e:
            api_not_enabled, _ = _api_not_enabled(e)
            if api_not_enabled:
                return False
            raise api_errors.ApiExecutionError(project_id, e) 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:21,代碼來源:compute.py

示例14: get_organization_sinks

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def get_organization_sinks(self, org_id):
        """Get information about organization sinks.
        Args:
            org_id (str): The id of the organization.
        Returns:
            list: The response of retrieving the organization sinks.
        Raises:
            ApiExecutionError: ApiExecutionError is raised if the call to the
                GCP API fails.
        """
        name = self.repository.organizations_sinks.get_name(org_id)

        try:
            paged_results = self.repository.organizations_sinks.list(name)
            flattened_results = api_helpers.flatten_list_results(paged_results,
                                                                 'sinks')
            LOGGER.debug('Getting information about organization sinks,'
                         ' org_id = %s, flattened_results = %s',
                         org_id, flattened_results)
            return flattened_results
        except (errors.HttpError, HttpLib2Error) as e:
            api_exception = api_errors.ApiExecutionError(
                'organizations_sinks', e, 'name', name)
            LOGGER.exception(api_exception)
            raise api_exception 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:27,代碼來源:stackdriver_logging.py

示例15: get_folder_sinks

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import HttpLib2Error [as 別名]
def get_folder_sinks(self, folder_id):
        """Get information about folder sinks.
        Args:
            folder_id (str): The id of the folder.
        Returns:
            list: The response of retrieving the folder sinks.
        Raises:
            ApiExecutionError: ApiExecutionError is raised if the call to the
                GCP API fails.
        """
        name = self.repository.folders_sinks.get_name(folder_id)

        try:
            paged_results = self.repository.folders_sinks.list(name)
            flattened_results = api_helpers.flatten_list_results(paged_results,
                                                                 'sinks')
            LOGGER.debug('Getting information about folder sinks,'
                         ' folder_id = %s, flattened_results = %s',
                         folder_id, flattened_results)
            return flattened_results
        except (errors.HttpError, HttpLib2Error) as e:
            api_exception = api_errors.ApiExecutionError(
                'folders_sinks', e, 'name', name)
            LOGGER.exception(api_exception)
            raise api_exception 
開發者ID:forseti-security,項目名稱:forseti-security,代碼行數:27,代碼來源:stackdriver_logging.py


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