当前位置: 首页>>代码示例>>Python>>正文


Python errors.HttpError方法代码示例

本文整理汇总了Python中googleapiclient.errors.HttpError方法的典型用法代码示例。如果您正苦于以下问题:Python errors.HttpError方法的具体用法?Python errors.HttpError怎么用?Python errors.HttpError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在googleapiclient.errors的用法示例。


在下文中一共展示了errors.HttpError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: publish

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def publish(client, body, topic):
    """Publish a message to a Pub/Sub topic."""
    project = 'projects/{}'.format(utils.get_project_id())
    dest_topic = project + '/topics/' + topic

    @backoff.on_exception(
        backoff.expo, HttpError, max_tries=3, giveup=utils.fatal_code)
    def _do_request():
        client.projects().topics().publish(
            topic=dest_topic, body=body).execute()

    try:
        _do_request()
    except HttpError as e:
        logging.error(e)
        raise PubSubException(e) 
开发者ID:doitintl,项目名称:iris,代码行数:18,代码来源:pubsub.py

示例2: pull

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def pull(client, sub, endpoint):
    """Register a listener endpoint."""
    subscription = get_full_subscription_name(utils.get_project_id(), sub)
    body = {'pushConfig': {'pushEndpoint': endpoint}}

    @backoff.on_exception(
        backoff.expo, HttpError, max_tries=3, giveup=utils.fatal_code)
    def _do_request():
        client.projects().subscriptions().modifyPushConfig(
            subscription=subscription, body=body).execute()

    try:
        _do_request()
    except HttpError as e:

        logging.error(e)
        return 'Error', 500
    return 'ok, 204' 
开发者ID:doitintl,项目名称:iris,代码行数:20,代码来源:pubsub.py

示例3: do_tag

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def do_tag(self, project_id):

        page_token = None
        more_results = True
        while more_results:
            try:
                response = self.storage.buckets().list(
                    project=project_id, pageToken=page_token).execute()
            except errors.HttpError as e:
                logging.error(e)
                return
            if 'items' in response:
                for bucket in response['items']:
                    self.tag_one(bucket, project_id)
            if 'nextPageToken' in response:
                page_token = response['nextPageToken']
            else:
                more_results = False
        if self.counter > 0:
            self.do_batch() 
开发者ID:doitintl,项目名称:iris,代码行数:22,代码来源:gcs.py

示例4: get_disk

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def get_disk(self, project_id, zone, name):
        """
       get an instance
        Args:
            zone: zone
            project_id: project id
            name: instance name
        Returns:
        """
        try:
            result = self.compute.disks().get(
                project=project_id, zone=zone,
                disk=name).execute()
        except errors.HttpError as e:
            logging.error(e)
            return None
        return result 
开发者ID:doitintl,项目名称:iris,代码行数:19,代码来源:gcedisks.py

示例5: get_snapshot

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def get_snapshot(self, project_id, name):
        """
       get an instance
        Args:
            project_id: project id
            name: instance name
        Returns:
        """

        try:
            result = self.compute.snapshots().get(
                project=project_id,
                snapshot=name).execute()
        except errors.HttpError as e:
            logging.error(e)
            return None
        return result 
开发者ID:doitintl,项目名称:iris,代码行数:19,代码来源:gcesnaphots.py

示例6: get_instance

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def get_instance(self, project_id, zone, name):
        """
       get an instance
        Args:
            zone: zone
            project_id: project id
            name: instance name
        Returns:
        """

        try:
            result = self.compute.instances().get(
                project=project_id, zone=zone,
                instance=name).execute()
        except errors.HttpError as e:
            logging.error(e)
            return None
        return result 
开发者ID:doitintl,项目名称:iris,代码行数:20,代码来源:gce.py

示例7: do_tag

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def do_tag(self, project_id):
        page_token = None
        more_results = True
        while more_results:
            try:
                result = self.bigtable.projects().instances().list(
                    parent="projects/" + project_id,
                    pageToken=page_token).execute()
            except errors.HttpError as e:
                logging.error(e)
                return
            if 'instances' in result:
                for inst in result['instances']:
                    self.tag_one(inst, project_id)
            if 'nextPageToken' in result:
                page_token = result['nextPageToken']
            else:
                more_results = False
            if self.counter > 0:
                self.do_batch() 
开发者ID:doitintl,项目名称:iris,代码行数:22,代码来源:bigtable.py

示例8: check_connection

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def check_connection(flags=None):
    """ Checks if link to google sheet is correctly set up. """
    try:
        credentials = _get_credentials(flags)
        http = credentials.authorize(httplib2.Http())
        discovery_url = 'https://sheets.googleapis.com/$discovery/rest?version=v4'
        service = discovery.build('sheets', 'v4', http=http, discoveryServiceUrl=discovery_url)

        title_cell = 'B2'
        title_cell_expected_content = 'Logs'

        result = service.spreadsheets().values().get(
            spreadsheetId=_get_spreadsheet_id(), range=title_cell).execute()
        values = result.get('values')
        if not values:
            raise GoogleSheetsAccessFailedException('No values found')
        if values[0][0] != title_cell_expected_content:
            raise GoogleSheetsAccessFailedException('Unexpected content found: {}'.format(values))
        print('Google Sheets connection established')
        return service
    except HttpError as e:
        raise GoogleSheetsAccessFailedException('HttpError: {}'.format(e)) 
开发者ID:fab-jul,项目名称:imgcomp-cvpr,代码行数:24,代码来源:sheets_logger.py

示例9: get

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def get(self):
    """Retrieves the information associated with a given Project ID.

    Returns:
      A dictionary object representing a deployed Google App Engine application
          (Type: google.appengine.v1.Application).

    Raises:
      NotFoundError: when unable to find a Google App Engine application for the
          provided Google Cloud Project ID.
    """
    try:
      return self._client.apps().get(appsId=self._config.project).execute()
    except errors.HttpError as err:
      logging.error(_GET_ERROR_MSG, self._config.project, err)
      raise NotFoundError(_GET_ERROR_MSG % (self._config.project, err)) 
开发者ID:google,项目名称:loaner,代码行数:18,代码来源:app_engine.py

示例10: disable_chrome_device

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def disable_chrome_device(self, device_id):
    """Disable a Chrome device within an organization.

    Args:
      device_id: String, The unique Chrome device id.

    Raises:
      DirectoryRPCError: An error when the RPC call to the directory API fails.
    """
    logging.info('Disabling chrome device %s.', device_id)
    try:
      self._client.chromeosdevices().action(
          customerId=constants.CUSTOMER_ID,
          resourceId=device_id,
          body={
              'action': 'disable'
          }).execute()
    except errors.HttpError as err:
      if err.resp.status == httplib.PRECONDITION_FAILED:
        raise DeviceAlreadyDisabledError(err.resp.reason)
      logging.error(
          'Directory API call to disable Chrome device failed with a %s '
          'exception because %s.', str(type(err)), err.resp.reason)
      raise DirectoryRPCError(err.resp.reason) 
开发者ID:google,项目名称:loaner,代码行数:26,代码来源:directory.py

示例11: reenable_chrome_device

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def reenable_chrome_device(self, device_id):
    """Re-enable a Chrome device within an organization.

    Args:
      device_id: String, The unique Chrome device id.

    Raises:
      DirectoryRPCError: An error when the RPC call to the directory API fails.
    """
    logging.info('Re-enabling chrome device %s.', device_id)
    try:
      self._client.chromeosdevices().action(
          customerId=constants.CUSTOMER_ID,
          resourceId=device_id,
          body={
              'action': 'reenable'
          }).execute()
    except errors.HttpError as err:
      logging.error(
          'Directory API call to reenable Chrome device failed with a %s '
          'exception because %s.', str(type(err)), err.resp.reason)
      raise DirectoryRPCError(err.resp.reason) 
开发者ID:google,项目名称:loaner,代码行数:24,代码来源:directory.py

示例12: given_name

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def given_name(self, user_email):
    """Get the given name of a user.

    Args:
      user_email: String, The email address of the user.

    Returns:
      A string containing the given name for a user.

    Raises:
      DirectoryRPCError: An error when the RPC call to the directory API fails.
    """
    try:
      return self._client.users().get(
          userKey=user_email,
          fields=constants.USER_NAME_FIELDS_MASK).execute()['name']['givenName']
    except errors.HttpError as err:
      logging.error(
          'Directory API given_name failed with a %s exception because %s.',
          str(type(err)), err.resp.reason)
      raise DirectoryRPCError(err.resp.reason)
    except KeyError as err:
      logging.info(
          'The given name for this user (%s) does not exist.', user_email)
      raise GivenNameDoesNotExistError(str(err)) 
开发者ID:google,项目名称:loaner,代码行数:27,代码来源:directory.py

示例13: _users_in_group

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def _users_in_group(self, group_email, page_token=None):
    """List the users in a group.

    Args:
      group_email: String, The email address of the group for whose users to
        return.
      page_token: String, The optional page token to query for.

    Returns:
      A dictionary based on a JSON object of kind admin#directory#members.
        For reference: https://goo.gl/YXiFq1

    Raises:
      DirectoryRPCError: An error when the RPC call to the directory API fails.
    """
    try:
      return self._client.members().list(
          groupKey=group_email,
          pageToken=page_token,
          fields=constants.GROUP_MEMBER_FIELDS_MASK).execute()
    except errors.HttpError as err:
      logging.error(
          'Directory API group members failed with a %s exception because %s.',
          str(type(err)), err.resp.reason)
      raise DirectoryRPCError(err.resp.reason) 
开发者ID:google,项目名称:loaner,代码行数:27,代码来源:directory.py

示例14: watch_gdrive

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def watch_gdrive():
    if not config.config_google_drive_watch_changes_response:
        with open(gdriveutils.CLIENT_SECRETS, 'r') as settings:
            filedata = json.load(settings)
        if filedata['web']['redirect_uris'][0].endswith('/'):
            filedata['web']['redirect_uris'][0] = filedata['web']['redirect_uris'][0][:-((len('/gdrive/callback')+1))]
        else:
            filedata['web']['redirect_uris'][0] = filedata['web']['redirect_uris'][0][:-(len('/gdrive/callback'))]
        address = '%s/gdrive/watch/callback' % filedata['web']['redirect_uris'][0]
        notification_id = str(uuid4())
        try:
            result = gdriveutils.watchChange(gdriveutils.Gdrive.Instance().drive, notification_id,
                               'web_hook', address, gdrive_watch_callback_token, current_milli_time() + 604800*1000)
            config.config_google_drive_watch_changes_response = json.dumps(result)
            # after save(), config_google_drive_watch_changes_response will be a json object, not string
            config.save()
        except HttpError as e:
            reason=json.loads(e.content)['error']['errors'][0]
            if reason['reason'] == u'push.webhookUrlUnauthorized':
                flash(_(u'Callback domain is not verified, please follow steps to verify domain in google developer console'), category="error")
            else:
                flash(reason['message'], category="error")

    return redirect(url_for('admin.configuration')) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:26,代码来源:gdrive.py

示例15: delete_message

# 需要导入模块: from googleapiclient import errors [as 别名]
# 或者: from googleapiclient.errors import HttpError [as 别名]
def delete_message(
            self,
            msg_id,
            user_id='me'):
        """Delete a Message.

        :param msg_id: ID of Message to delete.
        :param user_id: User's email address. The special value "me"
            can be used to indicate the authenticated user.
        :rtype: `None`
        """
        self.connect()
        try:
            self.client.users().messages().delete(
                userId=user_id,
                id=msg_id
            ).execute()
        except (socks.HTTPError, errors.HttpError) as error:
            logger.error('An error occurred: %s', error)
        else:
            logger.info('Message with id: %s deleted successfully.', msg_id) 
开发者ID:linkedin,项目名称:iris-relay,代码行数:23,代码来源:gmail.py


注:本文中的googleapiclient.errors.HttpError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。