本文整理汇总了Python中google.api_core.exceptions.NotFound方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.NotFound方法的具体用法?Python exceptions.NotFound怎么用?Python exceptions.NotFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.api_core.exceptions
的用法示例。
在下文中一共展示了exceptions.NotFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_table
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def _get_table(self, connection, table_name, schema=None):
if isinstance(connection, Engine):
connection = connection.connect()
project, dataset, table_name_prepared = self._split_table_name(table_name)
if dataset is None:
if schema is not None:
dataset = schema
elif self.dataset_id:
dataset = self.dataset_id
table = connection.connection._client.dataset(dataset, project=project).table(table_name_prepared)
try:
t = connection.connection._client.get_table(table)
except NotFound as e:
raise NoSuchTableError(table_name)
return t
示例2: test_get_conn_uri_non_existent_key
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def test_get_conn_uri_non_existent_key(self, mock_client_callable, mock_get_creds):
mock_get_creds.return_value = CREDENTIALS, PROJECT_ID
mock_client = mock.MagicMock()
mock_client_callable.return_value = mock_client
# The requested secret id or secret version does not exist
mock_client.access_secret_version.side_effect = NotFound('test-msg')
secrets_manager_backend = CloudSecretManagerBackend(connections_prefix=CONNECTIONS_PREFIX)
secret_id = secrets_manager_backend.build_path(CONNECTIONS_PREFIX, CONN_ID, SEP)
with self.assertLogs(secrets_manager_backend.client.log, level="ERROR") as log_output:
self.assertIsNone(secrets_manager_backend.get_conn_uri(conn_id=CONN_ID))
self.assertEqual([], secrets_manager_backend.get_connections(conn_id=CONN_ID))
self.assertRegex(
log_output.output[0],
f"GCP API Call Error \\(NotFound\\): Secret ID {secret_id} not found"
)
示例3: create_subscription
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def create_subscription(self, subscription, topic):
"""Handles creating the subscription when it does not exists.
This makes it easier to deploy a worker and forget about the
subscription side of things. The subscription must
have a topic to subscribe to. Which means that the topic must be
created manually before the worker is started.
:param subscription: str Subscription name
:param topic: str Topic name to subscribe
"""
subscription_path = self._client.subscription_path(
self._gc_project_id, subscription
)
topic_path = self._client.topic_path(self._gc_project_id, topic)
with suppress(exceptions.AlreadyExists):
try:
self._client.create_subscription(
name=subscription_path,
topic=topic_path,
ack_deadline_seconds=self._ack_deadline,
)
except exceptions.NotFound:
logger.error("Cannot subscribe to a topic that does not exist.")
示例4: download_file
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [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)
示例5: exists
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def exists(self, table_id):
""" Check if a table exists in Google BigQuery
Parameters
----------
table : str
Name of table to be verified
Returns
-------
boolean
true if table exists, otherwise false
"""
from google.api_core.exceptions import NotFound
table_ref = self.client.dataset(self.dataset_id).table(table_id)
try:
self.client.get_table(table_ref)
return True
except NotFound:
return False
except self.http_error as ex:
self.process_http_error(ex)
示例6: delete
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def delete(self, table_id):
""" Delete a table in Google BigQuery
Parameters
----------
table : str
Name of table to be deleted
"""
from google.api_core.exceptions import NotFound
if not self.exists(table_id):
raise NotFoundException("Table does not exist")
table_ref = self.client.dataset(self.dataset_id).table(table_id)
try:
self.client.delete_table(table_ref)
except NotFound:
# Ignore 404 error which may occur if table already deleted
pass
except self.http_error as ex:
self.process_http_error(ex)
示例7: test_queue
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def test_queue():
client = tasks_v2.CloudTasksClient()
parent = client.location_path(TEST_PROJECT_ID, TEST_LOCATION)
queue = {
# The fully qualified path to the queue
'name': client.queue_path(
TEST_PROJECT_ID, TEST_LOCATION, TEST_QUEUE_NAME),
}
q = client.create_queue(parent, queue)
yield q
try:
# Attempt to delete the queue in case the sample failed.
client.delete_queue(q.name)
except exceptions.NotFound:
# The queue was already successfully deleted.
print('Queue already deleted successfully')
示例8: secret
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def secret(client, project_id):
parent = client.project_path(project_id)
secret_id = 'python-secret-{}'.format(uuid.uuid4())
print('creating secret {}'.format(secret_id))
secret = client.create_secret(parent, secret_id, {
'replication': {
'automatic': {},
},
})
yield project_id, secret_id
print('deleting secret {}'.format(secret_id))
try:
client.delete_secret(secret.name)
except exceptions.NotFound:
# Secret was already deleted, probably in the test
pass
示例9: tenant
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def tenant():
tenant_ext_unique_id = "TEST_TENANT_{}".format(uuid.uuid4())
# create a temporary tenant
tenant_name = job_search_create_tenant.create_tenant(
PROJECT_ID, tenant_ext_unique_id
)
# extract company id
tenant_id = tenant_name.split("/")[-1]
yield tenant_id
try:
job_search_delete_tenant.delete_tenant(PROJECT_ID, tenant_id)
except NotFound as e:
print("Ignoring NotFound upon cleanup, details: {}".format(e))
示例10: job
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def job(tenant, company):
post_unique_id = "TEST_POST_{}".format(uuid.uuid4().hex)[:20]
# create a temporary job
job_name = job_search_create_job.create_job(
PROJECT_ID, tenant, company, post_unique_id, "www.jobUrl.com"
)
# extract company id
job_id = job_name.split("/")[-1]
yield job_id
try:
job_search_delete_job.delete_job(PROJECT_ID, tenant, job_id)
except NotFound as e:
print("Ignoring NotFound upon cleanup, details: {}".format(e))
示例11: test_topic
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def test_topic():
pubsub_client = pubsub.PublisherClient()
try:
topic = manager.create_iot_topic(project_id, topic_id)
except AlreadyExists as e:
print("The topic already exists, detail: {}".format(str(e)))
# Ignore the error, fetch the topic
topic = pubsub_client.get_topic(
pubsub_client.topic_path(project_id, topic_id))
yield topic
topic_path = pubsub_client.topic_path(project_id, topic_id)
try:
pubsub_client.delete_topic(topic_path)
except NotFound as e:
# We ignore this case.
print("The topic doesn't exist: detail: {}".format(str(e)))
示例12: test_subscription
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def test_subscription(test_topic):
subscriber = pubsub.SubscriberClient()
subscription_path = subscriber.subscription_path(
project_id, subscription_name)
try:
subscription = subscriber.create_subscription(
subscription_path, test_topic.name)
except AlreadyExists as e:
print("The topic already exists, detail: {}".format(str(e)))
# Ignore the error, fetch the subscription
subscription = subscriber.get_subscription(subscription_path)
yield subscription
try:
subscriber.delete_subscription(subscription_path)
except NotFound as e:
# We ignore this case.
print("The subscription doesn't exist: detail: {}".format(str(e)))
示例13: test_registry_id
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def test_registry_id(test_topic):
@backoff.on_exception(backoff.expo, HttpError, max_time=60)
def create_registry():
manager.open_registry(
service_account_json, project_id, cloud_region, test_topic.name,
registry_id)
create_registry()
yield registry_id
@backoff.on_exception(backoff.expo, HttpError, max_time=60)
def delete_registry():
try:
manager.delete_registry(
service_account_json, project_id, cloud_region, registry_id)
except NotFound as e:
# We ignore this case.
print("The registry doesn't exist: detail: {}".format(str(e)))
delete_registry()
示例14: ensure_dataset_ready
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def ensure_dataset_ready():
dataset = None
name = STATIC_DATASET
try:
dataset = automl_tables_dataset.get_dataset(PROJECT, REGION, name)
except exceptions.NotFound:
dataset = automl_tables_dataset.create_dataset(PROJECT, REGION, name)
if dataset.example_count is None or dataset.example_count == 0:
automl_tables_dataset.import_data(PROJECT, REGION, name, GCS_DATASET)
dataset = automl_tables_dataset.get_dataset(PROJECT, REGION, name)
automl_tables_dataset.update_dataset(
PROJECT,
REGION,
dataset.display_name,
target_column_spec_name="Deposit",
)
return dataset
示例15: get_current_calibration
# 需要导入模块: from google.api_core import exceptions [as 别名]
# 或者: from google.api_core.exceptions import NotFound [as 别名]
def get_current_calibration(self, project_id: str, processor_id: str
) -> Optional[qtypes.QuantumCalibration]:
"""Returns the current quantum calibration for a processor if it has
one.
Params:
project_id: A project_id of the parent Google Cloud Project.
processor_id: The processor unique identifier.
Returns:
The quantum calibration or None if there is no current calibration.
"""
try:
return self._make_request(
lambda: self.grpc_client.get_quantum_calibration(
self._processor_name_from_ids(project_id, processor_id) +
'/calibrations/current'))
except EngineException as err:
if isinstance(err.__cause__, NotFound):
return None
raise