pyrogram / pyrogram

Elegant, modern and asynchronous Telegram MTProto API framework in Python for users and bots
https://pyrogram.org
GNU Lesser General Public License v3.0
4.43k stars 1.43k forks source link

Pyrogram v2.0.106. The server sent an unknown constructor #1460

Open rTiRe opened 2 weeks ago

rTiRe commented 2 weeks ago

Checklist

Description

Sometimes after client.invoke() I get this error:

The server sent an unknown constructor: (...)

Steps to reproduce

This appears randomly and not always.

Code example

No response

Logs

bot-bot-1              | Task exception was never retrieved
bot-bot-1              | future: <Task finished name='Task-20680' coro=<Session.handle_packet() done, defined at /usr/local/lib/python3.11/site-packages/pyrogram/session/session.py:186> exception=ValueError('The server sent an unknown constructor: 0xfe4478bd\n8a505203 e6e4b9f5 f66b79db')>
bot-bot-1              | Traceback (most recent call last):
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/crypto/mtproto.py", line 70, in unpack
bot-bot-1              |     message = Message.read(data)
bot-bot-1              |               ^^^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/raw/core/message.py", line 46, in read
bot-bot-1              |     return Message(TLObject.read(BytesIO(body)), msg_id, seq_no, length)
bot-bot-1              |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/raw/core/tl_object.py", line 33, in read
bot-bot-1              |     return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
bot-bot-1              |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/raw/types/rpc_result.py", line 66, in read
bot-bot-1              |     result = TLObject.read(b)
bot-bot-1              |              ^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/raw/core/tl_object.py", line 33, in read
bot-bot-1              |     return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
bot-bot-1              |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/raw/types/contacts/resolved_peer.py", line 80, in read
bot-bot-1              |     chats = TLObject.read(b)
bot-bot-1              |             ^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/raw/core/tl_object.py", line 33, in read
bot-bot-1              |     return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
bot-bot-1              |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/raw/core/primitives/vector.py", line 49, in read
bot-bot-1              |     return List(
bot-bot-1              |            ^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/raw/core/primitives/vector.py", line 51, in <genexpr>
bot-bot-1              |     else Vector.read_bare(data, size)
bot-bot-1              |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/raw/core/primitives/vector.py", line 40, in read_bare
bot-bot-1              |     return TLObject.read(b)
bot-bot-1              |            ^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/raw/core/tl_object.py", line 33, in read
bot-bot-1              |     return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
bot-bot-1              |                           ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bot-bot-1              | KeyError: 4265900221
bot-bot-1              | 
bot-bot-1              | During handling of the above exception, another exception occurred:
bot-bot-1              | 
bot-bot-1              | Traceback (most recent call last):
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/session/session.py", line 187, in handle_packet
bot-bot-1              |     data = await self.loop.run_in_executor(
bot-bot-1              |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
bot-bot-1              |     result = self.fn(*self.args, **self.kwargs)
bot-bot-1              |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bot-bot-1              |   File "/usr/local/lib/python3.11/site-packages/pyrogram/crypto/mtproto.py", line 81, in unpack
bot-bot-1              |     raise ValueError(f"The server sent an unknown constructor: {hex(e.args[0])}\n{left}")
bot-bot-1              | ValueError: The server sent an unknown constructor: 0xfe4478bd
bot-bot-1              | 8a505203 e6e4b9f5 f66b79db
Danstiv commented 2 weeks ago

Hello @rTiRe!

  1. This may be a problem on the telegram servers side.
  2. This may be due to support/compatibility issues with the old tl schema (it hasn't been updated in over a year).
  3. See this comment.

If it's reason 2, then try using a fork with a fresh schema, like this one.

rTiRe commented 2 weeks ago

Also I get:

ValueError: The server sent an unknown constructor: 0x94345242
ValueError: The server sent an unknown constructor: 0xabb5f120
ValueError: The server sent an unknown constructor: 0xaadfc8f
ValueError: The server sent an unknown constructor: 0x4fe1cc86
rTiRe commented 2 weeks ago

Привет@rTiRe!

  1. Это может быть проблема на стороне серверов Telegram.
  2. Это может быть связано с проблемами поддержки/совместимости старой схемы tl (она не обновлялась больше года).
  3. См. этот комментарий .

Если причина 2, то попробуйте использовать форк с новой схемой, например, такой .

Thank you, I will try this!

I don't think it's my case that it's point number three, because I often get the same codes rather than different ones, which would probably be the case if I receive mixed updates.