I have some troubles with my client app in telegram. When I run my code, I have to confirm my account everytime (in the telegram itself, I need to enter the phone number and the code that came to the mail). The most interesting moment, that my code doesn’t contain anything criminal. Just for testing
import asyncio
import configparser
from telethon.sync import TelegramClient
config = configparser.ConfigParser()
config.read("config.ini")
api_id = config['Telegram']['api_id']
api_hash = config['Telegram']['api_hash']
username = config['Telegram']['username']
client = TelegramClient(username, api_id, api_hash)
client.start()
async def main():
await asyncio.sleep(3)
with client:
client.loop.run_until_complete(main())
Month ago, everything was working fine. Then I was doing a small chat scraper for checking swear words. I would like to know, why such a problem has appeared now
3
Answers
Make sure the script is not terminating abruptly. If it is, the library won’t have a chance to properly save the information. I would also recommend checking the active sessions from a different client, to learn whether Telethon’s session is somehow "disappearing" on its own. And lastly,
logging.DEBUG
logs may have some hints.I have the same issue as you, when using telethon, my Telegram account would log out everywhere for no reason, even when I wasn’t even doing anything in my code except starting client. Everything would work perfectly for ~30 seconds. It wouldn’t ask me to log in again within that timeframe, but then it just disconnected all my sessions. Not only that, if I relogged with my mobile app too soon, it would disconnect me after ~30 seconds again. I’ve tried everything, but it seems to be some account-specific issue, because after I switched to a brand new account everything works as supposed to.
I have exactly the same issue, plus it logs me out of all my sessions on all devices. This is most likely an update on Telegram’s side. Moreover, telethon might have received an update.
I read somewhere that you need to pass a parameter to TelegramClient called system_version, where you have to pass in the version of your device. Apparently you can get it in debug mode in TG by sending a message. It should output an array of information like this:
Apparently all these parameters exist in TelegramClient(). I suppose system version is the most important in this case. I read a discussion on that here: https://github.com/LonamiWebs/Telethon/issues/4051
Someone simply passed in
system_version="4.16.30-vxCUSTOM"
and it worked.I’m trying to get this to work right now, after Telegram lets me in again.
UPD: Passing in system_version variable does work for me.