我该如何恢复Telethon电报中的旧会话并再次连接(无需再次发送代码)) [英] how i can restore sessions old in telethon telegram and connect this again(without send again code))

查看:1456
本文介绍了我该如何恢复Telethon电报中的旧会话并再次连接(无需再次发送代码))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此脚本在Telethon中建立连接并建立会话

i use this script for connect and create sessions in telethon

from telethon import TelegramClient
from telethon.tl.functions.messages import GetHistoryRequest
from telethon.utils import get_input_peer
api_id = 7****
api_hash = 'ef584d*****************'
client = TelegramClient('+15159947451', api_id, api_hash)
client.connect()
if not client.is_user_authorized():
    client.send_code_request('+15159947451')
client.sign_in('+15159947451', cod)

使用此编码,我可以在此电报中良好登录并创建文件:+ 15159947451.session.

with this cod i can login good in this number telegram and create file:+15159947451.session.

现在我关闭并断开连接,如何再次使用该文件+ 15159947451.session登录该号码.

now i close and disconnect, how i can again login this number with this file +15159947451.session.

我使用此代码,但此代码有错误:

i use this code but this code have error:

from telethon import TelegramClient
from telethon.tl.functions.messages import GetHistoryRequest
from telethon.utils import get_input_peer
api_id = 7****
api_hash = 'ef584d180eee*******************'
number='+15152934803'
client = TelegramClient('00', api_id, api_hash)
client.session.try_load_or_create_new(session_user_id='+15159947451')
client.connect()

但是我有这个错误

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

推荐答案

问题是此行:

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

您不必将电话号码作为第一个参数.您必须传递会话的名称,例如'myname'.

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'.

您得到了:

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

因为您已经更改了会话的名称(现在称为"00"),但尚未在该会话上进行记录.因此,为了简单地解决您的问题:

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)

然后删除.send_code_request(...)行:

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

请注意,如果您为尚不存在的某些.session更改了"some_name",则必须再次创建它.另外,您可以将.session文件重命名为所需的任何名称,并将其名称用作参数(因为它已经存在).

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).

这篇关于我该如何恢复Telethon电报中的旧会话并再次连接(无需再次发送代码))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆