python - 使用 Telethon 查找会话 ID 并终止会话
问题描述
在我问这个问题之前,我检查了这里。我想杀死除了我现在连接的会话之外的所有其他会话。基于我使用的 Telethon api all_sessions = client(GetAuthorizationsRequest()).to_dict()
,我得到了这个结果:
{
'_': 'Authorization',
'api_id': ...,
'app_name': '...',
'app_version': '4.1.4',
'country': 'Unknown',
'date_active': ...,
'date_created': ...,
'device_model': 'SamsungSM-G920F',
'flags': 0,
'hash': ...,
'ip': '...',
'platform': 'Android',
'region': '',
'system_version': 'SDK 23'
}
我想终止这个会话,但我不知道session id
上面的链接中提到了什么(telethon API 文档)。我尝试使用这些命令:
client(DestroySessionRequest(api_id))
client(DestroySessionRequest(hash))
但不仅没有删除会话,而且没有来自 api 的响应,并且命令等待并等待响应没有错误或没有异常。我怎样才能终止会话?
解决方案
要终止其他会话,您需要使用该ResetAuthorizationRequest
功能。
来自官方文档的示例:
from telethon.sync import TelegramClient
from telethon import functions, types
with TelegramClient(name, api_id, api_hash) as client:
result = client(functions.account.ResetAuthorizationRequest(hash=-12398745604826))
print(result)
https://lonamiwebs.github.io/Telethon/methods/account/reset_authorization.html#examples
推荐阅读
- php - 更改列类型 Laravel 5
- angularjs - 删除多个 MD 菜单容器
- python - Python Django:更改在另一个列表中找到的部分字符串的字体颜色
- python - 数字列表和具有单个数字元组的列表有什么区别?
- machine-learning - 多输入多输出自动编码器
- haskell - 创建自定义 happstack 响应代码
- sql - 查询一个时间窗口中不存在于另一个时间窗口中的结果
- mysql - 在 GROUP BY 语句中获取平均值
- python - BeautifulSoup 中的 findAll() 会跳过多个 id
- javascript - 试图为javascript设置超时值但不工作