當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。