登录我的帐户时,Telethon 不断将我注销。电报、Python

alt*_*t4s 5 python telegram telethon

该代码似乎运行完美,在我最终再次注销之前,我什至有时间用机器人对其进行了短暂的测试。此时我已经尝试了大约 10 次,但 Telethon 似乎出于某种原因将我从手机上的 Telegram 中删除了。我不知道为什么会发生这种情况,而且我也没有看到其他人遇到过这个问题。

负责登录的代码片段:

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)
Run Code Online (Sandbox Code Playgroud)