2017-11-20 07:12:31 +03:00
|
|
|
==========
|
|
|
|
RPC Errors
|
|
|
|
==========
|
|
|
|
|
2018-01-14 12:53:29 +03:00
|
|
|
RPC stands for Remote Procedure Call, and when the library raises
|
|
|
|
a ``RPCError``, it's because you have invoked some of the API
|
2017-11-20 07:12:31 +03:00
|
|
|
methods incorrectly (wrong parameters, wrong permissions, or even
|
2018-01-14 12:53:29 +03:00
|
|
|
something went wrong on Telegram's server). All the errors are
|
|
|
|
available in :ref:`telethon-errors-package`, but some examples are:
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-01-05 15:30:21 +03:00
|
|
|
- ``FloodWaitError`` (420), the same request was repeated many times.
|
2019-02-27 21:30:12 +03:00
|
|
|
Must wait ``.seconds`` (you can access this attribute). For example:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
...
|
|
|
|
from telethon import errors
|
|
|
|
|
|
|
|
try:
|
|
|
|
print(client.get_messages(chat)[0].text)
|
|
|
|
except errors.FloodWaitError as e:
|
|
|
|
print('Have to sleep', e.seconds, 'seconds')
|
|
|
|
time.sleep(e.seconds)
|
|
|
|
|
2017-11-20 07:12:31 +03:00
|
|
|
- ``SessionPasswordNeededError``, if you have setup two-steps
|
|
|
|
verification on Telegram.
|
|
|
|
- ``CdnFileTamperedError``, if the media you were trying to download
|
|
|
|
from a CDN has been altered.
|
2018-01-05 02:59:53 +03:00
|
|
|
- ``ChatAdminRequiredError``, you don't have permissions to perform
|
2017-11-20 07:12:31 +03:00
|
|
|
said operation on a chat or channel. Try avoiding filters, i.e. when
|
|
|
|
searching messages.
|
|
|
|
|
2018-01-06 15:37:46 +03:00
|
|
|
The generic classes for different error codes are:
|
|
|
|
|
|
|
|
- ``InvalidDCError`` (303), the request must be repeated on another DC.
|
|
|
|
- ``BadRequestError`` (400), the request contained errors.
|
|
|
|
- ``UnauthorizedError`` (401), the user is not authorized yet.
|
|
|
|
- ``ForbiddenError`` (403), privacy violation error.
|
|
|
|
- ``NotFoundError`` (404), make sure you're invoking ``Request``\ 's!
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-01-05 02:59:53 +03:00
|
|
|
If the error is not recognised, it will only be an ``RPCError``.
|
2019-02-27 21:30:12 +03:00
|
|
|
|
|
|
|
You can refer to all errors from Python through the ``telethon.errors``
|
|
|
|
module. If you don't know what attributes they have, try printing their
|
|
|
|
dir (like ``print(dir(e))``).
|