Exceptions¶
Exceptions raised by Google API core & clients.
This module provides base classes for all errors raised by libraries based
on google.api_core
, including both HTTP and gRPC clients.
-
exception
google.api_core.exceptions.
Aborted
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.Conflict
Exception mapping a
grpc.StatusCode.ABORTED
error.
-
exception
google.api_core.exceptions.
AlreadyExists
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.Conflict
Exception mapping a
grpc.StatusCode.ALREADY_EXISTS
error.
-
exception
google.api_core.exceptions.
BadGateway
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ServerError
Exception mapping a
502 Bad Gateway
response.
-
exception
google.api_core.exceptions.
BadRequest
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ClientError
Exception mapping a
400 Bad Request
response.
-
exception
google.api_core.exceptions.
Cancelled
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ClientError
Exception mapping a
grpc.StatusCode.CANCELLED
error.
-
exception
google.api_core.exceptions.
ClientError
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.GoogleAPICallError
Base class for all client error (HTTP 4xx) responses.
-
exception
google.api_core.exceptions.
Conflict
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ClientError
Exception mapping a
409 Conflict
response.
-
exception
google.api_core.exceptions.
DataLoss
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ServerError
Exception mapping a
grpc.StatusCode.DATA_LOSS
error.
-
exception
google.api_core.exceptions.
DeadlineExceeded
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.GatewayTimeout
Exception mapping a
grpc.StatusCode.DEADLINE_EXCEEDED
error.
-
exception
google.api_core.exceptions.
FailedPrecondition
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.BadRequest
Exception mapping a
grpc.StatusCode.FAILED_PRECONDITION
error.
-
exception
google.api_core.exceptions.
Forbidden
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ClientError
Exception mapping a
403 Forbidden
response.
-
exception
google.api_core.exceptions.
GatewayTimeout
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ServerError
Exception mapping a
504 Gateway Timeout
response.
-
exception
google.api_core.exceptions.
GoogleAPICallError
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.GoogleAPIError
Base class for exceptions raised by calling API methods.
- Parameters
message (str) – The exception message.
errors (Sequence[Any]) – An optional list of error details.
response (Union[requests.Request, grpc.Call]) – The response or gRPC call metadata.
-
code
= None¶ The HTTP status code associated with this error.
This may be
None
if the exception does not have a direct mapping to an HTTP error.See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
- Type
Optional[int]
-
property
errors
¶ Detailed error information.
- Returns
A list of additional error details.
- Return type
Sequence[Any]
-
grpc_status_code
= None¶ The gRPC status code associated with this error.
This may be
None
if the exception does not match up to a gRPC error.- Type
Optional[grpc.StatusCode]
-
property
response
¶ The response or gRPC call metadata.
- Type
Optional[Union[requests.Request, grpc.Call]]
-
exception
google.api_core.exceptions.
GoogleAPIError
[source]¶ Bases:
Exception
Base class for all exceptions raised by Google API Clients.
-
exception
google.api_core.exceptions.
InternalServerError
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ServerError
Exception mapping a
500 Internal Server Error
response. or agrpc.StatusCode.INTERNAL
error.
-
exception
google.api_core.exceptions.
InvalidArgument
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.BadRequest
Exception mapping a
grpc.StatusCode.INVALID_ARGUMENT
error.
-
exception
google.api_core.exceptions.
LengthRequired
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ClientError
Exception mapping a
411 Length Required
response.
-
exception
google.api_core.exceptions.
MethodNotAllowed
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ClientError
Exception mapping a
405 Method Not Allowed
response.
-
exception
google.api_core.exceptions.
MethodNotImplemented
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ServerError
Exception mapping a
501 Not Implemented
response or agrpc.StatusCode.UNIMPLEMENTED
error.
-
exception
google.api_core.exceptions.
MovedPermanently
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.Redirection
Exception mapping a
301 Moved Permanently
response.
-
exception
google.api_core.exceptions.
NotFound
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ClientError
Exception mapping a
404 Not Found
response or agrpc.StatusCode.NOT_FOUND
error.
-
exception
google.api_core.exceptions.
NotModified
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.Redirection
Exception mapping a
304 Not Modified
response.
-
exception
google.api_core.exceptions.
OutOfRange
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.BadRequest
Exception mapping a
grpc.StatusCode.OUT_OF_RANGE
error.
-
exception
google.api_core.exceptions.
PermissionDenied
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.Forbidden
Exception mapping a
grpc.StatusCode.PERMISSION_DENIED
error.
-
exception
google.api_core.exceptions.
PreconditionFailed
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ClientError
Exception mapping a
412 Precondition Failed
response.
-
exception
google.api_core.exceptions.
Redirection
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.GoogleAPICallError
Base class for for all redirection (HTTP 3xx) responses.
-
exception
google.api_core.exceptions.
RequestRangeNotSatisfiable
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ClientError
Exception mapping a
416 Request Range Not Satisfiable
response.
-
exception
google.api_core.exceptions.
ResourceExhausted
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.TooManyRequests
Exception mapping a
grpc.StatusCode.RESOURCE_EXHAUSTED
error.
-
exception
google.api_core.exceptions.
ResumeIncomplete
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.Redirection
Exception mapping a
308 Resume Incomplete
response.Note
http_client.PERMANENT_REDIRECT
is308
, but Google APIs differ in their use of this status code.
-
exception
google.api_core.exceptions.
RetryError
(message, cause)[source]¶ Bases:
google.api_core.exceptions.GoogleAPIError
Raised when a function has exhausted all of its available retries.
- Parameters
-
property
cause
¶ The last exception raised when retrying the function.
-
exception
google.api_core.exceptions.
ServerError
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.GoogleAPICallError
Base for 5xx responses.
Bases:
google.api_core.exceptions.ServerError
Exception mapping a
503 Service Unavailable
response or agrpc.StatusCode.UNAVAILABLE
error.
-
exception
google.api_core.exceptions.
TemporaryRedirect
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.Redirection
Exception mapping a
307 Temporary Redirect
response.
-
exception
google.api_core.exceptions.
TooManyRequests
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ClientError
Exception mapping a
429 Too Many Requests
response.
-
exception
google.api_core.exceptions.
Unauthenticated
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.Unauthorized
Exception mapping a
grpc.StatusCode.UNAUTHENTICATED
error.
Bases:
google.api_core.exceptions.ClientError
Exception mapping a
401 Unauthorized
response.
-
exception
google.api_core.exceptions.
Unknown
(message, errors=(), response=None)[source]¶ Bases:
google.api_core.exceptions.ServerError
Exception mapping a
grpc.StatusCode.UNKNOWN
error.
-
google.api_core.exceptions.
exception_class_for_grpc_status
(status_code)[source]¶ Return the exception class for a specific
grpc.StatusCode
.- Parameters
status_code (grpc.StatusCode) – The gRPC status code.
- Returns
the appropriate subclass of
GoogleAPICallError
.- Return type
type()
-
google.api_core.exceptions.
exception_class_for_http_status
(status_code)[source]¶ Return the exception class for a specific HTTP status code.
- Parameters
status_code (int) – The HTTP status code.
- Returns
the appropriate subclass of
GoogleAPICallError
.- Return type
type()
-
google.api_core.exceptions.
from_grpc_error
(rpc_exc)[source]¶ Create a
GoogleAPICallError
from agrpc.RpcError
.- Parameters
rpc_exc (grpc.RpcError) – The gRPC error.
- Returns
- An instance of the appropriate subclass of
- Return type
-
google.api_core.exceptions.
from_grpc_status
(status_code, message, **kwargs)[source]¶ Create a
GoogleAPICallError
from agrpc.StatusCode
.- Parameters
status_code (grpc.StatusCode) – The gRPC status code.
message (str) – The exception message.
kwargs – Additional arguments passed to the
GoogleAPICallError
constructor.
- Returns
- An instance of the appropriate subclass of
- Return type
-
google.api_core.exceptions.
from_http_response
(response)[source]¶ Create a
GoogleAPICallError
from arequests.Response
.- Parameters
response (requests.Response) – The HTTP response.
- Returns
- An instance of the appropriate subclass of
GoogleAPICallError
, with the message and errors populated from the response.
- Return type
-
google.api_core.exceptions.
from_http_status
(status_code, message, **kwargs)[source]¶ Create a
GoogleAPICallError
from an HTTP status code.- Parameters
status_code (int) – The HTTP status code.
message (str) – The exception message.
kwargs – Additional arguments passed to the
GoogleAPICallError
constructor.
- Returns
- An instance of the appropriate subclass of
- Return type