Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# telegram.error Module

This module contains classes that represent Telegram errors.

Changed in version 20.0: Replaced `Unauthorized` by `Forbidden`.

exception telegram.error.BadRequest(message)

  Bases: `telegram.error.NetworkError`

  Raised when Telegram could not process the request correctly.

exception telegram.error.ChatMigrated(new_chat_id)

  Bases: `telegram.error.TelegramError`

  Raised when the requested group chat migrated to supergroup and has a new chat id.

  See also

  Storing Bot, User and Chat Related Data

  Parameters:

    new_chat_id (`int`) – The new chat id of the group.

  new_chat_id

    The new chat id of the group.

    Type:

      `int`

  __reduce__()

    Defines how to serialize the exception for pickle.

    See also

    `object.__reduce__()`, `pickle`.

    Returns:

      `tuple`

exception telegram.error.Conflict(message)

  Bases: `telegram.error.TelegramError`

  Raised when a long poll or webhook conflicts with another one.

  __reduce__()

    Defines how to serialize the exception for pickle.

    See also

    `object.__reduce__()`, `pickle`.

    Returns:

      `tuple`

exception telegram.error.EndPointNotFound(message)

  Bases: `telegram.error.TelegramError`

  Raised when the requested endpoint is not found. Only relevant for `telegram.Bot.do_api_request()`.

  Added in version 20.8.

exception telegram.error.Forbidden(message)

  Bases: `telegram.error.TelegramError`

  Raised when the bot has not enough rights to perform the requested action.

  Examples

  Raw API Bot

  Changed in version 20.0: This class was previously named `Unauthorized`.

exception telegram.error.InvalidToken(message=None)

  Bases: `telegram.error.TelegramError`

  Raised when the token is invalid.

  Parameters:

    message (`str`, optional) –

    Any additional information about the exception.

    Added in version 20.0.

exception telegram.error.NetworkError(message)

  Bases: `telegram.error.TelegramError`

  Base class for exceptions due to networking errors.

  Tip

  This exception (and its subclasses) usually originates from the networking backend used by `HTTPXRequest`, or a custom implementation of `BaseRequest`. In this case, the original exception can be accessed via the `__cause__` attribute.

  Examples

  Raw API Bot

  See also

  Handling network errors

exception telegram.error.PassportDecryptionError(message)

  Bases: `telegram.error.TelegramError`

  Something went wrong with decryption.

  Changed in version 20.0: This class was previously named `TelegramDecryptionError` and was available via `telegram.TelegramDecryptionError`.

  __reduce__()

    Defines how to serialize the exception for pickle.

    See also

    `object.__reduce__()`, `pickle`.

    Returns:

      `tuple`

exception telegram.error.RetryAfter(retry_after)

  Bases: `telegram.error.TelegramError`

  Raised when flood limits where exceeded.

  Changed in version 20.0: `retry_after` is now an integer to comply with the Bot API.

  Parameters:

    retry_after (`int`) – Time in seconds, after which the bot can retry the request.

  retry_after

    Time in seconds, after which the bot can retry the request.

    Type:

      `int`

  __reduce__()

    Defines how to serialize the exception for pickle.

    See also

    `object.__reduce__()`, `pickle`.

    Returns:

      `tuple`

exception telegram.error.TelegramError(message)

  Bases: `Exception`

  Base class for Telegram errors.

  Tip

  Objects of this type can be serialized via Python’s `pickle` module and pickled objects from one version of PTB are usually loadable in future versions. However, we can not guarantee that this compatibility will always be provided. At least a manual one-time conversion of the data may be needed on major updates of the library.

  See also

  Exceptions, Warnings and Logging

  __reduce__()

    Defines how to serialize the exception for pickle.

    See also

    `object.__reduce__()`, `pickle`.

    Returns:

      `tuple`

  __repr__()

    Gives an unambiguous string representation of the exception.

    Returns:

      `str`

  __str__()

    Gives the string representation of exceptions message.

    Returns:

      `str`

exception telegram.error.TimedOut(message=None)

  Bases: `telegram.error.NetworkError`

  Raised when a request took too long to finish.

  See also

  Handling network errors

  Parameters:

    message (`str`, optional) –

    Any additional information about the exception.

    Added in version 20.0.