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)[source]¶
Bases:
telegram.error.NetworkErrorRaised when Telegram could not process the request correctly.
- exception telegram.error.ChatMigrated(new_chat_id)[source]¶
Bases:
telegram.error.TelegramErrorRaised when the requested group chat migrated to supergroup and has a new chat id.
- Parameters:
new_chat_id (
int) – The new chat id of the group.
- exception telegram.error.Conflict(message)[source]¶
Bases:
telegram.error.TelegramErrorRaised when a long poll or webhook conflicts with another one.
- exception telegram.error.EndPointNotFound(message)[source]¶
Bases:
telegram.error.TelegramErrorRaised 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)[source]¶
Bases:
telegram.error.TelegramErrorRaised when the bot has not enough rights to perform the requested action.
Examples
Changed in version 20.0: This class was previously named
Unauthorized.
- exception telegram.error.InvalidToken(message=None)[source]¶
Bases:
telegram.error.TelegramErrorRaised 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)[source]¶
Bases:
telegram.error.TelegramErrorBase 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 ofBaseRequest. In this case, the original exception can be accessed via the__cause__attribute.Examples
See also
- exception telegram.error.PassportDecryptionError(message)[source]¶
Bases:
telegram.error.TelegramErrorSomething went wrong with decryption.
Changed in version 20.0: This class was previously named
TelegramDecryptionErrorand was available viatelegram.TelegramDecryptionError.
- exception telegram.error.RetryAfter(retry_after)[source]¶
Bases:
telegram.error.TelegramErrorRaised when flood limits where exceeded.
Changed in version 20.0:
retry_afteris now an integer to comply with the Bot API.- Parameters:
retry_after (
int|datetime.timedelta) –Time in seconds, after which the bot can retry the request.
Changed in version v22.2:
datetime.timedeltaobjects are accepted in addition to plainintvalues.
- retry_after[source]¶
Time in seconds, after which the bot can retry the request.
Deprecated since version v22.2: In a future major version this attribute will be of type
datetime.timedelta. You can opt-in early by setting PTB_TIMEDELTA=true orPTB_TIMEDELTA=1as an environment variable.- Type:
- exception telegram.error.TelegramError(message)[source]¶
Bases:
ExceptionBase class for Telegram errors.
Tip
Objects of this type can be serialized via Python’s
picklemodule 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
- exception telegram.error.TimedOut(message=None)[source]¶
Bases:
telegram.error.NetworkErrorRaised when a request took too long to finish.
See also
- Parameters:
message (
str, optional) –Any additional information about the exception.
Added in version 20.0.