how i can restore sessions old in telethon telegram and connect this again(without send again code))

后端 未结 2 1060
旧巷少年郎
旧巷少年郎 2021-01-16 12:19

i use this script for connect and create sessions in telethon

from telethon import TelegramClient
from telethon.tl.functions.messages import GetHistoryReques         


        
2条回答
  •  孤独总比滥情好
    2021-01-16 12:38

    The problem is this line:

    client = TelegramClient('+15xxxxxxxxx', api_id, api_hash)
    

    You don't have to pass your phone number as a first parameter. You have to pass the name of the session, for instance, 'myname'.

    You get this:

    telethon.errors.RPCError: (RPCError(...), 'AUTH_KEY_UNREGISTERED (401):       The key is not registered in the system.')
    

    Because you've changed the name of the session (and now called it '00'), and you haven't logged it on that one. So in order to solve your problem simply:

    client = TelegramClient('some_name', api_id, api_hash)
    client.connect()
    if not client.is_user_authorized():
        client.send_code_request('+15xxxxxxxxx')
        client.sign_in('+15xxxxxxxxx', cod)
    

    And then remove the .send_code_request(...) line:

    client = TelegramClient('some_name', api_id, api_hash)
    client.connect()
    

    Notice that if you change 'some_name' for some .session that doesn't exist yet, you will have to create it again. Also, you can rename the .session file to any name you want, and use its name as a parameter (since it already exists).

提交回复
热议问题