Telethon - change session file path

Viewed 1777

I want to reuse existing session file (the phonenumber.session) file,

But I want to change it default path (working directory) to another directory, like '/data/se.session'

There is any option to do that in telethon?

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

When using TLSharp, the TelegramClient constructor get session file path as input..

1 Answers

After looking at telethon source code, I found 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.

In general, when creating TelegramClient object - pass it the full path to session file

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