Skip to content

The server sent an unknown constructor #177

@vedma1337

Description

@vedma1337

Checklist

  • I am sure the error is coming from Pyrogram's code and not elsewhere
  • I have searched in the issue tracker for similar bug reports, including closed ones
  • I ran pip3 install https://github.com/TelegramPlayground/pyrogram/archive/dev.zip --force-reinstall and reproduced the issue using the latest development version

Description

With any code after 10-15 seconds of userbot running it will start giving errors like this:
ValueError: The server sent an unknown constructor:

Steps to reproduce

  1. Launch userbot
  2. Wait 10-15 seconds
  3. Get an error flooded

Code example

from pyrogram import Client, filters

app = Client("session")

@app.on_message(filters.private)
async def hello(client, message):
    await message.reply("Hello from Pyrogram!")

app.run()

Logs

2025-05-10 21:40:22,359 - pyrogram.connection.connection - INFO - Connecting...
2025-05-10 21:40:22,460 - pyrogram.connection.connection - INFO - Connected! Production DC2 - IPv4 - TCPAbridgedO
2025-05-10 21:40:22,461 - pyrogram.session.session - INFO - NetworkTask started
2025-05-10 21:40:22,887 - pyrogram.session.session - INFO - Session initialized: Layer 203
2025-05-10 21:40:22,887 - pyrogram.session.session - INFO - Device: CPython 3.13.2 - Pyrogram 2.2.12
2025-05-10 21:40:22,888 - pyrogram.session.session - INFO - System: Windows 10 (EN)
2025-05-10 21:40:22,888 - pyrogram.session.session - INFO - Session started
2025-05-10 21:40:22,890 - pyrogram.session.session - INFO - PingTask started
2025-05-10 21:40:23,306 - pyrogram.dispatcher - INFO - Started 12 HandlerTasks
2025-05-10 21:40:24,431 - asyncio - ERROR - Task exception was never retrieved
future: <Task finished name='Task-34' coro=<Session.handle_packet() done, defined at C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\session\session.py:201> exception=ValueError('The server sent an unknown constructor: 0x5c62d151\nceaf5e4f 8c2ef1bf 4a1d6eb9 d996e151 9319c118')>
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\crypto\mtproto.py", line 70, in unpack
    message = Message.read(data)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\message.py", line 46, in read
    return Message(TLObject.read(BytesIO(body)), msg_id, seq_no, length)
                   ~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\tl_object.py", line 33, in read
    return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\types\updates_t.py", line 200, in read
    updates = TLObject.read(b)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\tl_object.py", line 33, in read
    return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\primitives\vector.py", line 65, in read
    return List(
        t.read(data) if t
        else Vector.read_bare(data, size)
        for _ in range(count)
    )
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\primitives\vector.py", line 67, in <genexpr>       
    else Vector.read_bare(data, size)
         ~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\primitives\vector.py", line 56, in read_bare       
    return TLObject.read(b)
           ~~~~~~~~~~~~~^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\tl_object.py", line 33, in read
    return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\types\update_new_channel_message.py", line 68, in read  
    message = TLObject.read(b)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\tl_object.py", line 33, in read
    return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\types\message.py", line 255, in read
    media = TLObject.read(b) if flags & (1 << 9) else None
            ~~~~~~~~~~~~~^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\tl_object.py", line 33, in read
    return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\types\message_media_web_page.py", line 91, in read      
    webpage = TLObject.read(b)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\tl_object.py", line 33, in read
    return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\types\web_page.py", line 163, in read
    attributes = TLObject.read(b) if flags & (1 << 12) else []
                 ~~~~~~~~~~~~~^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\tl_object.py", line 33, in read
    return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\primitives\vector.py", line 65, in read
    return List(
        t.read(data) if t
        else Vector.read_bare(data, size)
        for _ in range(count)
    )
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\primitives\vector.py", line 67, in <genexpr>       
    else Vector.read_bare(data, size)
         ~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\primitives\vector.py", line 56, in read_bare       
    return TLObject.read(b)
           ~~~~~~~~~~~~~^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\tl_object.py", line 33, in read
    return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\types\web_page_attribute_unique_star_gift.py", line 60, 
in read
    gift = TLObject.read(b)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\raw\core\tl_object.py", line 33, in read
    return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
                          ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 1549979985

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\session\session.py", line 203, in handle_packet
    data = await self.loop.run_in_executor(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
    )
    ^
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\concurrent\futures\thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyrogram\crypto\mtproto.py", line 81, in unpack
    raise ValueError(f"The server sent an unknown constructor: {hex(e.args[0])}\n{left}")
ValueError: The server sent an unknown constructor: 0x5c62d151
ceaf5e4f 8c2ef1bf 4a1d6eb9 d996e151 9319c118
2025-05-10 21:40:28,049 - pyrogram.methods.utilities.idle - INFO - Stop signal received (SIGINT). Exiting...
2025-05-10 21:40:28,053 - pyrogram.dispatcher - INFO - Stopped 12 HandlerTasks
2025-05-10 21:40:28,053 - pyrogram.session.session - INFO - PingTask stopped
2025-05-10 21:40:28,053 - pyrogram.connection.connection - INFO - Disconnected
2025-05-10 21:40:28,054 - pyrogram.session.session - INFO - NetworkTask stopped
2025-05-10 21:40:28,054 - pyrogram.session.session - INFO - Session stopped

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions