本文整理匯總了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