本文整理汇总了Python中google.api_core.exceptions.Conflict方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.Conflict方法的具体用法?Python exceptions.Conflict怎么用?Python exceptions.Conflict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.api_core.exceptions
的用法示例。
在下文中一共展示了exceptions.Conflict方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import Conflict [as 别名]
def execute(self, context):
bq_hook = BigQueryHook(
gcp_conn_id=self.gcp_conn_id,
delegate_to=self.delegate_to,
location=self.location
)
try:
bq_hook.create_empty_dataset(
project_id=self.project_id,
dataset_id=self.dataset_id,
dataset_reference=self.dataset_reference,
location=self.location,
exists_ok=False,
)
except Conflict:
dataset_id = self.dataset_reference.get("datasetReference", {}).get("datasetId", self.dataset_id)
self.log.info('Dataset %s already exists.', dataset_id)
示例2: test_upload_from_file_failure
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import Conflict [as 别名]
def test_upload_from_file_failure(self):
import requests
from google.resumable_media import InvalidResponse
from google.cloud import exceptions
message = "Someone is already in this spot."
response = requests.Response()
response.status_code = http_client.CONFLICT
response.request = requests.Request("POST", "http://example.com").prepare()
side_effect = InvalidResponse(response, message)
with self.assertRaises(exceptions.Conflict) as exc_info:
self._upload_from_file_helper(side_effect=side_effect)
self.assertIn(message, exc_info.exception.message)
self.assertEqual(exc_info.exception.errors, [])
示例3: tearDown
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import Conflict [as 别名]
def tearDown(self):
def _still_in_use(bad_request):
return any(
error["reason"] == "resourceInUse" for error in bad_request._errors
)
retry_in_use = RetryErrors(BadRequest, error_predicate=_still_in_use)
retry_storage_errors_conflict = RetryErrors(
(Conflict, TooManyRequests, InternalServerError, ServiceUnavailable)
)
for doomed in self.to_delete:
if isinstance(doomed, storage.Bucket):
retry_storage_errors_conflict(doomed.delete)(force=True)
elif isinstance(doomed, (Dataset, bigquery.DatasetReference)):
retry_in_use(Config.CLIENT.delete_dataset)(doomed, delete_contents=True)
elif isinstance(doomed, (Table, bigquery.TableReference)):
retry_in_use(Config.CLIENT.delete_table)(doomed)
else:
doomed.delete()
示例4: _fetch_dataset
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import Conflict [as 别名]
def _fetch_dataset(self, dataset_id):
"""Fetch a BigQuery Dataset if it exists, else, create a new one
Parameters
----------
dataset_id : str
ID to name the created Dataset
Returns
-------
:class:`google.cloud.bigquery.dataset.Dataset`
The Dataset class to build tables from
"""
dataset_ref = self.client.dataset(dataset_id)
dataset = bigquery.Dataset(dataset_ref)
try:
dataset = self.client.create_dataset(dataset)
except Conflict:
dataset = self.client.get_dataset(dataset_ref)
return dataset
示例5: execute
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import Conflict [as 别名]
def execute(self, context):
hook = GCSHook(
google_cloud_storage_conn_id=self.gcp_conn_id,
delegate_to=self.delegate_to
)
try:
hook.create_bucket(bucket_name=self.bucket_name,
resource=self.resource,
storage_class=self.storage_class,
location=self.location,
project_id=self.project_id,
labels=self.labels)
except Conflict: # HTTP 409
self.log.warning("Bucket %s already exists", self.bucket_name)
示例6: tearDownModule
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import Conflict [as 别名]
def tearDownModule():
errors = (exceptions.Conflict, exceptions.TooManyRequests)
retry = RetryErrors(errors, max_tries=15)
retry(_empty_bucket)(Config.TEST_BUCKET)
retry(Config.TEST_BUCKET.delete)(force=True)
示例7: tearDownClass
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import Conflict [as 别名]
def tearDownClass(cls):
_empty_bucket(cls.bucket)
errors = (exceptions.Conflict, exceptions.TooManyRequests)
retry = RetryErrors(errors, max_tries=6)
retry(cls.bucket.delete)(force=True)
示例8: create_view
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import Conflict [as 别名]
def create_view(bigquery_client, sql, table_ref):
table = bigquery.Table(table_ref)
table.view_query = sql
logging.info('Creating view: ' + json.dumps(table.to_api_repr()))
try:
table = bigquery_client.create_table(table)
except Conflict:
# https://cloud.google.com/bigquery/docs/managing-views
table = bigquery_client.update_table(table, ['view_query'])
assert table.table_id == table_ref.table_id
示例9: create_dataset
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import Conflict [as 别名]
def create_dataset(client, dataset_name, project=None):
dataset = client.dataset(dataset_name, project=project)
try:
logging.info('Creating new dataset ...')
dataset = client.create_dataset(dataset)
logging.info('New dataset created: ' + dataset_name)
except Conflict as error:
logging.info('Dataset already exists')
return dataset