當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.Conflict方法代碼示例

本文整理匯總了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) 
開發者ID:apache,項目名稱:airflow,代碼行數:20,代碼來源:bigquery.py

示例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, []) 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:19,代碼來源:test_blob.py

示例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() 
開發者ID:googleapis,項目名稱:python-bigquery,代碼行數:21,代碼來源:system.py

示例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 
開發者ID:thinkingmachines,項目名稱:geomancer,代碼行數:23,代碼來源:bq.py

示例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) 
開發者ID:apache,項目名稱:airflow,代碼行數:16,代碼來源:gcs.py

示例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) 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:7,代碼來源:test_system.py

示例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) 
開發者ID:googleapis,項目名稱:python-storage,代碼行數:7,代碼來源:test_system.py

示例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 
開發者ID:blockchain-etl,項目名稱:ethereum-etl-airflow,代碼行數:14,代碼來源:bigquery_utils.py

示例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 
開發者ID:blockchain-etl,項目名稱:ethereum-etl-airflow,代碼行數:12,代碼來源:parse_logic.py


注:本文中的google.api_core.exceptions.Conflict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。