Exceptions

exception itsdangerous.exc.BadData(message)

Raised if bad data of any sort was encountered. This is the base for all exceptions that ItsDangerous defines.

Changelog

Added in version 0.15.

Parameters:

message (str)

exception itsdangerous.exc.BadSignature(message, payload=None)

Raised if a signature does not match.

Parameters:
  • message (str)

  • payload (t.Any | None)

payload: Any | None

The payload that failed the signature test. In some situations you might still want to inspect this, even if you know it was tampered with.

Changelog

Added in version 0.14.

exception itsdangerous.exc.BadTimeSignature(message, payload=None, date_signed=None)

Raised if a time-based signature is invalid. This is a subclass of BadSignature.

Parameters:
  • message (str)

  • payload (Any | None)

  • date_signed (datetime | None)

date_signed

If the signature expired this exposes the date of when the signature was created. This can be helpful in order to tell the user how long a link has been gone stale.

Changelog

Changed in version 2.0: The datetime value is timezone-aware rather than naive.

Added in version 0.14.

exception itsdangerous.exc.SignatureExpired(message, payload=None, date_signed=None)

Raised if a signature timestamp is older than max_age. This is a subclass of BadTimeSignature.

Parameters:
  • message (str)

  • payload (Any | None)

  • date_signed (datetime | None)

exception itsdangerous.exc.BadHeader(message, payload=None, header=None, original_error=None)

Raised if a signed header is invalid in some form. This only happens for serializers that have a header that goes with the signature.

Changelog

Added in version 0.24.

Parameters:
  • message (str)

  • payload (Any | None)

  • header (t.Any | None)

  • original_error (Exception | None)

header: Any | None

If the header is actually available but just malformed it might be stored here.

original_error: Exception | None

If available, the error that indicates why the payload was not valid. This might be None.

exception itsdangerous.exc.BadPayload(message, original_error=None)

Raised if a payload is invalid. This could happen if the payload is loaded despite an invalid signature, or if there is a mismatch between the serializer and deserializer. The original exception that occurred during loading is stored on as original_error.

Changelog

Added in version 0.15.

Parameters:
original_error: Exception | None

If available, the error that indicates why the payload was not valid. This might be None.