[Python] Telethon keeps logging me out when signing into my account. Telegram, Python

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    The code seems to work perfectly, I've even had time to test it with the bot for a brief moment before I eventually got logged out again. I tried this about 10 times at this point, with telethon seemingly logging me out of telegram on my phone for some reason. I have no idea why this is happening, and I've not seen anyone else experience this problem.

    Snippet responsible for the log in:

    async def get_channel_messages(chat_id, msg_id):
    # Telegram API ID and Hash (you can get it from my.telegram.org)
    api_id = '12345678'
    api_hash = '1234'
    session_hash='hash'
    # Identify your bot with his ID number, can be found using this link
    my_bot_id = '12345'
    # Storing max 3 past messages
    max_memory_message = 3

    chat_id = int(chat_id)
    data = {}

    # Create a Telegram client with the given session string
    async with TelegramClient(StringSession(session_hash), api_id, api_hash) as client:
    # Connect to Telegram
    await client.connect()

    # Get the channel by its username
    channel = await client.get_entity(PeerChannel(chat_id))
    messages = await client.get_messages(channel, limit=100, offset_id=0)

    Continue reading...

Compartilhe esta Página