我想重用现有的会话文件(phonenumber.session)文件,
但我想将其默认路径(工作目录)更改为另一个目录,例如“/data/se.session”
在电视马拉松中有什么选择可以做到这一点?
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone)
client.sign_in(phone, input('Enter the code: '))
Run Code Online (Sandbox Code Playgroud)
使用TLSharp时,TelegramClient 构造函数获取会话文件路径作为输入。
查看 telethon 源代码后,我发现了这个,
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.
Run Code Online (Sandbox Code Playgroud)
一般来说,在创建 TelegramClient 对象时 - 将其传递给会话文件的完整路径
client = TelegramClient('path/to/session.session',api_id,app_hash)
Run Code Online (Sandbox Code Playgroud)