skip to Main Content

When I fast-run the code, it is executed properly, but when I try to run it a second time with a session, it gives me [Server sent a very new message with ID 90454444, ignoring].

from telethon import TelegramClient, sync
api_id = '*******'
api_hash = "***********"




# create a new Telegram client using your own API credentials

phone_number = '********'
client = TelegramClient('session_name', api_id, api_hash)

# try to load an existing session
if client.start():
    print('Session loaded successfully!')
else:
    # if no session is found, log in with the OTP and save the session
    client.send_code_request(phone_number)
    code = input('Enter the code: ')
    client.sign_in(phone_number, code)
    client.start()
    print('Session created successfully!')

# get the target chat or channel entity
entity = client.get_entity('******')

# get the list of messages
messages = client.get_messages(entity, limit=10)

# iterate over the messages and extract the desired information
for message in messages:
    print(f'{message.sender.username} ({message.date}): {message.text}')

# disconnect the client
client.disconnect()

2

Answers


  1. You may also see this error as "Server sent a very old message with ID".

    This is a security feature from Telethon that cannot be disabled and is
    meant to protect you against replay attacks.

    When this message is incorrectly reported as a "bug",
    the most common patterns seem to be:

    • Your system time is incorrect.
    • The proxy you’re using may be interfering somehow.
    • The Telethon session is being used or has been used from somewhere else.
      Make sure that you created the session from Telethon, and are not using the
      same session anywhere else. If you need to use the same account from
      multiple places, login and use a different session for each place you need.
    Login or Signup to reply.
  2. change the session name client = TelegramClient(‘other_session_name’, api_id, api_hash)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search