From aa5779b89a6a38a6134e055b8d4516880af393ce Mon Sep 17 00:00:00 2001 From: Alexander Bridges Date: Sun, 15 Oct 2017 14:00:25 +0300 Subject: [PATCH] add exception when pressing !h, sometimes TimeoutError and/or some other errors occurs due to network problems. The exception prevents the script from interruption and restarts the cycle, and allows to repeat the request without reloading the script. --- telethon_examples/interactive_telegram_client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/telethon_examples/interactive_telegram_client.py b/telethon_examples/interactive_telegram_client.py index 031a78cd..51360868 100644 --- a/telethon_examples/interactive_telegram_client.py +++ b/telethon_examples/interactive_telegram_client.py @@ -158,8 +158,11 @@ class InteractiveTelegramClient(TelegramClient): # History elif msg == '!h': # First retrieve the messages and some information - total_count, messages, senders = self.get_message_history( + try: + total_count, messages, senders = self.get_message_history( entity, limit=10) + except: + continue # Iterate over all (in reverse order so the latest appear # the last in the console) and print them with format: