I am using Telethon to connect to telegram API, and now after development I need to change project api to the main account. I am wondering where the credentials are stored by telethon so I can remove them and force re-authentication?
If you pass a str
as the session name, it will create a str.session
file on the same directory on which you ran your script. So, if you ever change the string you pass to the TelegramClient
constructor for a non-existing-yet one, it won't be able to login. In the same way, renaming or deleting that session would also work to get rid of that session. You shouldn't delete the session files manually, but rather call .log_out()
.
Although not related to the question itself, you're also free to override the Session
class to add custom .save()
and .load()
functionality. This issue shows when the format was changed from Pickle to JSON, and this one suggested the ability to actually override the Session
class. For instance:
from telethon.tl import Session
class MySession(Session):
pass # Override load and save as you wish here
Note that currently a migration from Session
to JsonSession
is being made, and eventually JsonSession
will replace the Session
(as of v0.10.1
), although this shouldn't affect you if you override the save and load.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With