Exceptions
CogniteAPIError
- exception cognite.client.exceptions.CogniteAPIError(message: str, code: int, x_request_id: ~typing.Optional[str] = None, missing: ~typing.Optional[list] = None, duplicated: ~typing.Optional[list] = None, successful: ~typing.Optional[list] = None, failed: ~typing.Optional[list] = None, unknown: ~typing.Optional[list] = None, skipped: ~typing.Optional[list] = None, unwrap_fn: ~collections.abc.Callable = <function no_op>, cluster: ~typing.Optional[str] = None, extra: ~typing.Optional[dict] = None)
Cognite API Error
Raised if a given request fails. If one or more of concurrent requests fails, this exception will also contain information about which items were successfully processed (2xx), which may have been processed (5xx), and which have failed to be processed (4xx).
- Parameters
message (str) – The error message produced by the API.
code (int) – The error code produced by the failure.
x_request_id (str | None) – The request-id generated for the failed request.
missing (list | None) – (List) List of missing identifiers.
duplicated (list | None) – (List) List of duplicated identifiers.
successful (list | None) – List of items which were successfully processed.
failed (list | None) – List of items which failed.
unknown (list | None) – List of items which may or may not have been successfully processed.
skipped (list | None) – List of items that were skipped due to “fail fast” mode.
unwrap_fn (Callable) – Function to extract identifier from the Cognite resource.
cluster (str | None) – Which Cognite cluster the user’s project is on.
extra (dict | None) – A dict of any additional information.
Examples
Catching an API-error and handling it based on the error code:
from cognite.client import CogniteClient from cognite.client.exceptions import CogniteAPIError client = CogniteClient() try: client.iam.token.inspect() except CogniteAPIError as e: if e.code == 401: print("You are not authorized") elif e.code == 400: print("Something is wrong with your request") elif e.code == 500: print(f"Something went terribly wrong. Here is the request-id: {e.x_request_id}" print(f"The message returned from the API: {e.message}")
CogniteNotFoundError
- exception cognite.client.exceptions.CogniteNotFoundError(not_found: list, successful: ~typing.Optional[list] = None, failed: ~typing.Optional[list] = None, unknown: ~typing.Optional[list] = None, skipped: ~typing.Optional[list] = None, unwrap_fn: ~collections.abc.Callable = <function no_op>)
Cognite Not Found Error
Raised if one or more of the referenced ids/external ids are not found.
- Parameters
not_found (list) – The ids not found.
successful (list | None) – List of items which were successfully processed.
failed (list | None) – List of items which failed.
unknown (list | None) – List of items which may or may not have been successfully processed.
skipped (list | None) – List of items that were skipped due to “fail fast” mode.
unwrap_fn (Callable) – No description.
CogniteDuplicatedError
- exception cognite.client.exceptions.CogniteDuplicatedError(duplicated: list, successful: ~typing.Optional[list] = None, failed: ~typing.Optional[list] = None, unknown: ~typing.Optional[list] = None, skipped: ~typing.Optional[list] = None, unwrap_fn: ~collections.abc.Callable = <function no_op>)
Cognite Duplicated Error
Raised if one or more of the referenced ids/external ids have been duplicated in the request.
- Parameters
duplicated (list) – The duplicated ids.
successful (list | None) – List of items which were successfully processed.
failed (list | None) – List of items which failed.
unknown (list | None) – List of items which may or may not have been successfully processed.
skipped (list | None) – List of items that were skipped due to “fail fast” mode.
unwrap_fn (Callable) – Function to extract identifier from the Cognite resource.
CogniteImportError
- exception cognite.client.exceptions.CogniteImportError(module: str, message: Optional[str] = None)
Cognite Import Error
Raised if the user attempts to use functionality which requires an uninstalled package.
- Parameters
module (str) – Name of the module which could not be imported
message (str | None) – The error message to output.