本文整理汇总了Python中google.api_core.exceptions.GoogleAPIError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.GoogleAPIError方法的具体用法?Python exceptions.GoogleAPIError怎么用?Python exceptions.GoogleAPIError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.api_core.exceptions
的用法示例。
在下文中一共展示了exceptions.GoogleAPIError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import GoogleAPIError [as 别名]
def run(self, params={}):
new_results = []
try:
query_job = self.connection.client.query(params.get(Input.QUERY))
results = query_job.result()
for result in results:
new_results.append(helper.clean_dict(result))
except GoogleAPIError as e:
self.logger.error(f"Google API error: Check query: {e}")
raise PluginException(cause="Google API error",
assistance="Check query",
data=e)
return {
Output.RESULT: new_results
}
示例2: download_file
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import GoogleAPIError [as 别名]
def download_file(self, blob, local_path, bucket_name=None, use_basename=True):
"""
Downloads a file from Google Cloud Storage.
Args:
blob: `str`. blob to download.
local_path: `str`. the path to download to.
bucket_name: `str`. the name of the bucket.
use_basename: `bool`. whether or not to use the basename of the blob.
"""
if not bucket_name:
bucket_name, blob = self.parse_gcs_url(blob)
local_path = os.path.abspath(local_path)
if use_basename:
local_path = append_basename(local_path, blob)
check_dirname_exists(local_path)
try:
blob = self.get_blob(blob=blob, bucket_name=bucket_name)
blob.download_to_filename(local_path)
except (NotFound, GoogleAPIError) as e:
raise PolyaxonStoresException(e)
示例3: _add_series
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import GoogleAPIError [as 别名]
def _add_series(project_id, series, client=None):
"""Write metrics series to Stackdriver.
Args:
project_id: series will be written to this project id's account
series: the time series to be written, as a list of
monitoring_v3.types.TimeSeries instances
client: optional monitoring_v3.MetricServiceClient will be used
instead of obtaining a new one
"""
client = client or monitoring_v3.MetricServiceClient()
project_name = client.project_path(project_id)
if isinstance(series, monitoring_v3.types.TimeSeries):
series = [series]
try:
client.create_time_series(project_name, series)
except GoogleAPIError as e:
raise Error('Error from monitoring API: %s' % e)
示例4: _fetch_quotas
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import GoogleAPIError [as 别名]
def _fetch_quotas(project, region='global', compute=None):
"""Fetch GCE per - project or per - region quotas from the API.
Args:
project: fetch global or regional quotas for this project id
region: which quotas to fetch, 'global' or region name
compute: optional instance of googleapiclient.discovery.build will be used
instead of obtaining a new one
"""
compute = compute or googleapiclient.discovery.build('compute', 'v1')
try:
if region != 'global':
req = compute.regions().get(project=project, region=region)
else:
req = compute.projects().get(project=project)
resp = req.execute()
return resp['quotas']
except (GoogleAPIError, googleapiclient.errors.HttpError) as e:
_LOGGER.debug('API Error: %s', e, exc_info=True)
raise Error('Error fetching quota (project: %s, region: %s)' %
(project, region))
示例5: delete_file
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import GoogleAPIError [as 别名]
def delete_file(self, key, bucket_name=None):
if not bucket_name:
bucket_name, key = self.parse_gcs_url(key)
bucket = self.get_bucket(bucket_name)
try:
return bucket.delete_blob(key)
except (NotFound, GoogleAPIError) as e:
raise PolyaxonStoresException(e)
示例6: download_file
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import GoogleAPIError [as 别名]
def download_file(self, blob, local_path, bucket_name=None, use_basename=True):
"""
Downloads a file from Google Cloud Storage.
Args:
blob: `str`. blob to download.
local_path: `str`. the path to download to.
bucket_name: `str`. the name of the bucket.
use_basename: `bool`. whether or not to use the basename of the blob.
"""
if not bucket_name:
bucket_name, blob = self.parse_gcs_url(blob)
local_path = os.path.abspath(local_path)
if use_basename:
local_path = append_basename(local_path, blob)
try:
check_dirname_exists(local_path)
except PolyaxonPathException as e:
raise PolyaxonStoresException("Connection error: %s" % e) from e
try:
blob = self.get_blob(blob=blob, bucket_name=bucket_name)
blob.download_to_filename(local_path)
except (NotFound, GoogleAPIError) as e:
raise PolyaxonStoresException("Connection error: %s" % e) from e
示例7: delete_file
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import GoogleAPIError [as 别名]
def delete_file(self, key, bucket_name=None):
if not bucket_name:
bucket_name, key = self.parse_gcs_url(key)
bucket = self.get_bucket(bucket_name)
try:
return bucket.delete_blob(key)
except (NotFound, GoogleAPIError) as e:
raise PolyaxonStoresException("Connection error: %s" % e) from e