RPC Errors

RPC stands for Remote Procedure Call. By extension, RPC Errors occur when a RPC fails to execute in the server. In Telethon, a RPC error corresponds to the RpcError class.

Telethon will only ever raise RpcError when the result to a RPC is an error. If the error is raised, you know it comes from Telegram. Consequently, when using Raw API directly, if a RpcError occurs, it is extremely unlikely to be a bug in the library. When RpcErrors are raised using the Raw API, Telegram is the one that decided an error should occur.

RPC error consist of an integer code and a string name. The RpcError.code is roughly the same as HTTP status codes. The RpcError.name is often a string in SCREAMING_CASE and refers to what went wrong.

Certain error names also contain an integer value. This value is removed from the name and put into RpcError.value. If Telegram responds with FLOOD_WAIT_60, the name would be 'FLOOD_WAIT' and the value 60.

A very common error is FLOOD_WAIT. It occurs when you have attempted to use a request too many times during a certain window of time:

import asyncio
from telethon import errors

try:
    await client.send_message('me', 'Spam')
except errors.FloodWait as e:
    # A flood error; sleep.
    await asyncio.sleep(e.value)

Note that the library can automatically handle and retry on FLOOD_WAIT for you. Refer to the flood_sleep_threshold of the Client to learn how.

Refer to the documentation of the telethon.errors pseudo-module for more details.