本文整理匯總了Python中google.api_core.exceptions.GoogleAPICallError方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.GoogleAPICallError方法的具體用法?Python exceptions.GoogleAPICallError怎麽用?Python exceptions.GoogleAPICallError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.api_core.exceptions
的用法示例。
在下文中一共展示了exceptions.GoogleAPICallError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: delete_instance
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def delete_instance(self, instance_id: str, project_id: str) -> None:
"""
Deletes an existing Cloud Spanner instance.
:param instance_id: The ID of the Cloud Spanner instance.
:type instance_id: str
:param project_id: Optional, the ID of the GCP project that owns the Cloud Spanner
database. If set to None or missing, the default project_id from the GCP connection is used.
:type project_id: str
:return: None
"""
instance = self._get_client(project_id=project_id).instance(instance_id)
try:
instance.delete()
return
except GoogleAPICallError as e:
self.log.error('An error occurred: %s. Exiting.', e.message)
raise e
示例2: glossary
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def glossary():
"""Get the ID of a glossary available to session (do not mutate/delete)."""
glossary_id = "test-{}".format(uuid.uuid4())
translate_v3_create_glossary.create_glossary(
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
)
yield glossary_id
# cleanup
@backoff.on_exception(
backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
)
def delete_glossary():
try:
translate_v3_delete_glossary.delete_glossary(
PROJECT_ID, glossary_id)
except NotFound as e:
# Ignoring this case.
print("Got NotFound, detail: {}".format(str(e)))
delete_glossary()
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:23,代碼來源:translate_v3_batch_translate_text_with_glossary_test.py
示例3: glossary
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def glossary():
"""Get the ID of a glossary available to session (do not mutate/delete)."""
glossary_id = "must-start-with-letters-" + str(uuid.uuid1())
translate_v3_create_glossary.create_glossary(
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
)
yield glossary_id
# clean up
@backoff.on_exception(
backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
)
def delete_glossary():
try:
translate_v3_delete_glossary.delete_glossary(
PROJECT_ID, glossary_id)
except NotFound as e:
# Ignoring this case.
print("Got NotFound, detail: {}".format(str(e)))
delete_glossary()
示例4: glossary
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def glossary():
"""Get the ID of a glossary available to session (do not mutate/delete)."""
glossary_id = "must-start-with-letters-" + str(uuid.uuid1())
translate_v3_create_glossary.create_glossary(
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
)
yield glossary_id
# cleanup
@backoff.on_exception(
backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
)
def delete_glossary():
try:
translate_v3_delete_glossary.delete_glossary(
PROJECT_ID, glossary_id)
except NotFound as e:
# Ignoring this case.
print("Got NotFound, detail: {}".format(str(e)))
delete_glossary()
示例5: test_create_glossary
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def test_create_glossary(capsys):
try:
glossary_id = "test-{}".format(uuid.uuid4())
translate_v3_create_glossary.create_glossary(
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
)
out, _ = capsys.readouterr()
# assert
assert "Created:" in out
assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out
finally:
# cleanup
@backoff.on_exception(
backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
)
def delete_glossary():
try:
translate_v3_delete_glossary.delete_glossary(
PROJECT_ID, glossary_id)
except NotFound as e:
# Ignoring this case.
print("Got NotFound, detail: {}".format(str(e)))
delete_glossary()
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:25,代碼來源:translate_v3_create_glossary_test.py
示例6: test_is_grpc_error
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def test_is_grpc_error(self):
import grpc
from google.api_core.exceptions import GoogleAPICallError
exc = grpc.RpcError()
result = self._callFUT(exc)
self.assertEqual(result.__class__, GoogleAPICallError)
示例7: _maybe_commit
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def _maybe_commit(self, transaction):
"""Try to commit the transaction.
If the transaction is read-write and the ``Commit`` fails with the
``ABORTED`` status code, it will be retried. Any other failure will
not be caught.
Args:
transaction
(:class:`~google.cloud.firestore_v1.transaction.Transaction`):
The transaction to be ``Commit``-ed.
Returns:
bool: Indicating if the commit succeeded.
"""
try:
transaction._commit()
return True
except exceptions.GoogleAPICallError as exc:
if transaction._read_only:
raise
if isinstance(exc, exceptions.Aborted):
# If a read-write transaction returns ABORTED, retry.
return False
else:
raise
示例8: _commit_with_retry
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def _commit_with_retry(client, write_pbs, transaction_id):
"""Call ``Commit`` on the GAPIC client with retry / sleep.
Retries the ``Commit`` RPC on Unavailable. Usually this RPC-level
retry is handled by the underlying GAPICd client, but in this case it
doesn't because ``Commit`` is not always idempotent. But here we know it
is "idempotent"-like because it has a transaction ID. We also need to do
our own retry to special-case the ``INVALID_ARGUMENT`` error.
Args:
client (:class:`~google.cloud.firestore_v1.client.Client`):
A client with GAPIC client and configuration details.
write_pbs (List[:class:`google.cloud.proto.firestore.v1.write_pb2.Write`, ...]):
A ``Write`` protobuf instance to be committed.
transaction_id (bytes):
ID of an existing transaction that this commit will run in.
Returns:
:class:`google.cloud.firestore_v1.types.CommitResponse`:
The protobuf response from ``Commit``.
Raises:
~google.api_core.exceptions.GoogleAPICallError: If a non-retryable
exception is encountered.
"""
current_sleep = _INITIAL_SLEEP
while True:
try:
return client._firestore_api.commit(
client._database_string,
write_pbs,
transaction=transaction_id,
metadata=client._rpc_metadata,
)
except exceptions.ServiceUnavailable:
# Retry
pass
current_sleep = _sleep(current_sleep)
示例9: _maybe_commit
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def _maybe_commit(self, transaction):
"""Try to commit the transaction.
If the transaction is read-write and the ``Commit`` fails with the
``ABORTED`` status code, it will be retried. Any other failure will
not be caught.
Args:
transaction (~.firestore_v1beta1.transaction.Transaction): The
transaction to be ``Commit``-ed.
Returns:
bool: Indicating if the commit succeeded.
"""
try:
transaction._commit()
return True
except exceptions.GoogleAPICallError as exc:
if transaction._read_only:
raise
if isinstance(exc, exceptions.Aborted):
# If a read-write transaction returns ABORTED, retry.
return False
else:
raise
示例10: test_delete_topic_api_call_error
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def test_delete_topic_api_call_error(self, mock_service):
mock_service.return_value.delete_topic.side_effect = GoogleAPICallError(
'Error deleting topic: %s' % EXPANDED_TOPIC
)
with self.assertRaises(PubSubException):
self.pubsub_hook.delete_topic(project_id=TEST_PROJECT, topic=TEST_TOPIC, fail_if_not_exists=True)
示例11: test_create_topic_api_call_error
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def test_create_topic_api_call_error(self, mock_service):
mock_service.return_value.create_topic.side_effect = GoogleAPICallError(
'Error creating topic: %s' % TEST_TOPIC
)
with self.assertRaises(PubSubException):
self.pubsub_hook.create_topic(project_id=TEST_PROJECT, topic=TEST_TOPIC, fail_if_exists=True)
示例12: test_delete_subscription_api_call_error
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def test_delete_subscription_api_call_error(self, mock_service):
mock_service.delete_subscription.side_effect = GoogleAPICallError(
'Error deleting subscription %s' % EXPANDED_SUBSCRIPTION
)
with self.assertRaises(PubSubException):
self.pubsub_hook.delete_subscription(
project_id=TEST_PROJECT, subscription=TEST_SUBSCRIPTION, fail_if_not_exists=True
)
示例13: test_create_subscription_api_call_error
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def test_create_subscription_api_call_error(self, mock_service):
mock_service.create_subscription.side_effect = GoogleAPICallError(
'Error creating subscription %s' % EXPANDED_SUBSCRIPTION
)
with self.assertRaises(PubSubException):
self.pubsub_hook.create_subscription(
project_id=TEST_PROJECT, topic=TEST_TOPIC, subscription=TEST_SUBSCRIPTION, fail_if_exists=True
)
示例14: test_publish_api_call_error
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def test_publish_api_call_error(self, mock_service):
publish_method = mock_service.return_value.publish
publish_method.side_effect = GoogleAPICallError(
'Error publishing to topic {}'.format(EXPANDED_SUBSCRIPTION)
)
with self.assertRaises(PubSubException):
self.pubsub_hook.publish(project_id=TEST_PROJECT, topic=TEST_TOPIC, messages=TEST_MESSAGES)
示例15: create_database
# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import GoogleAPICallError [as 別名]
def create_database(
self,
instance_id: str,
database_id: str,
ddl_statements: List[str],
project_id: str,
) -> None:
"""
Creates a new database in Cloud Spanner.
:type project_id: str
:param instance_id: The ID of the Cloud Spanner instance.
:type instance_id: str
:param database_id: The ID of the database to create in Cloud Spanner.
:type database_id: str
:param ddl_statements: The string list containing DDL for the new database.
:type ddl_statements: list[str]
:param project_id: Optional, the ID of the GCP project that owns the Cloud Spanner
database. If set to None or missing, the default project_id from the GCP connection is used.
:return: None
"""
instance = self._get_client(project_id=project_id).instance(
instance_id=instance_id)
if not instance.exists():
raise AirflowException("The instance {} does not exist in project {} !".
format(instance_id, project_id))
database = instance.database(database_id=database_id,
ddl_statements=ddl_statements)
try:
operation = database.create() # type: Operation
except GoogleAPICallError as e:
self.log.error('An error occurred: %s. Exiting.', e.message)
raise e
if operation:
result = operation.result()
self.log.info(result)