微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Telethon - 更改会话文件路径

如何解决Telethon - 更改会话文件路径

我想重用现有的会话文件(phonenumber.session)文件

但我想将其认路径(工作目录)更改为另一个目录,例如“/data/se.session”

在 Telethon 中可以选择这样做吗?

client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone)
    client.sign_in(phone,input('Enter the code: '))

使用 TLSharp 时,TelegramClient 构造函数获取会话文件路径作为输入..

解决方法

在查看了 Telethon 源代码后,我发现了 this

    session (`str` | `telethon.sessions.abstract.Session`,`None`):
        The file name of the session file to be used if a string is
        given (it may be a full path),or the Session instance to be
        used otherwise. If it's `None`,the session will not be saved,and you should call :meth:`.log_out()` when you're done.
        Note that if you pass a string it will be a file in the current
        working directory,although you can also pass absolute paths.
        The session file contains enough information for you to login
        without re-sending the code,so if you have to enter the code
        more than once,maybe you're changing the working directory,renaming or removing the file,or using random names.

通常,在创建 TelegramClient 对象时 - 将会话文件的完整路径传递给它

client = TelegramClient('path/to/session.session',api_id,app_hash)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。