Exceptions

CogniteAPIError

exception cognite.client.exceptions.CogniteAPIError(message: str, code: int, x_request_id: str | None = None, missing: list | None = None, duplicated: list | None = None, successful: list | None = None, failed: list | None = None, unknown: list | None = None, skipped: list | None = None, unwrap_fn: Callable = <function no_op>, extra: dict | None = 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.

  • 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: list | None = None, failed: list | None = None, unknown: list | None = None, skipped: list | None = None, unwrap_fn: 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: list | None = None, failed: list | None = None, unknown: list | None = None, skipped: list | None = None, unwrap_fn: 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: str | None = 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.

CogniteMissingClientError

exception cognite.client.exceptions.CogniteMissingClientError(obj: Any)

Cognite Missing Client Error

Raised if the user attempts to make use of a method which requires the cognite_client being set, but it is not.

Parameters

obj (Any) – Object missing client reference.