[Python] TELETHON Server sent a very old message with ID

Discussão em 'Python' iniciado por Stack, Setembro 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on a Python script. To call a specific function, I need to read the last message from a Telegram group chat once an hour.

    The first time I run the script, I don’t get any errors. However, in subsequent hours, I start seeing errors like the ones below. I get many of them, but here is one example:

    WARNING:telethon.network.mtprotostate:Server sent a very old message with ID XXXXXXXXXX, ignoring (see FAQ for details)
    WARNING:telethon.network.mtprotosender:Security error while unpacking a received message: Too many messages had to be ignored consecutively
    WARNING:telethon.network.mtprotostate:Server sent a very old message with ID XXXXXXXXXXX, ignoring (see FAQ for details)


    Should I ignore these messages and treat them as normal warnings, or should I change the implementation?

    P.S. : I clear the session_name.session file before running the script. I also tried using different operating systems (Ubuntu and Windows 10) to check for a possible system time issue.

    I initialize my Telegram client and then call the retrieveMessage function:

    self.loop = asyncio.get_event_loop()
    self.loop.run_until_complete(init_telegram())


    last_msg = self.loop.run_until_complete(retrieveMessage())

    Telegram class here:

    from telethon import TelegramClient
    import asyncio
    import os
    from dotenv import load_dotenv

    load_dotenv()
    # ---- CONFIG ----
    API_ID = os.getenv("API_ID")
    API_HASH = os.getenv("API_HASH")
    PHONE_NUMBER = os.getenv("PHONE")
    GROUP_NAME = os.getenv("GROUP_NAME")


    telegram_client = TelegramClient('session_name', API_ID, API_HASH)

    async def init_telegram():
    await telegram_client.start(PHONE_NUMBER)
    print("[INFO] Telegram client started and connected.")


    async def retrieveMessage():
    try:
    group = await telegram_client.get_entity(GROUP_NAME)
    messages = await telegram_client.get_messages(group, limit=1)
    if messages:
    return messages[0].text
    return None
    except Exception as e:
    print(f"Error retrieving message: {e}")
    return None

    Continue reading...

Compartilhe esta Página