From ed091422b20a859f4567b24a585722fe93f7f2a1 Mon Sep 17 00:00:00 2001 From: ferferga Date: Tue, 10 Apr 2018 20:56:35 +0200 Subject: [PATCH] Connection checks Instead of rasing an exception when running client.start() without an active internet connection, Telethon will handle it itself, advising the user to check his internet connection. The connection will be tried in a loop, until the connection is established, breaking the loop. --- telethon/telegram_client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index e619ee1f..ab7bd35c 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -297,7 +297,14 @@ class TelegramClient(TelegramBareClient): 'must only provide one of either') if not self.is_connected(): - self.connect() + connected = self.connect() + while connected is not True: + print("Couldn't establish a connection to Telegram's servers. Check your connection. Trying again...") + connected2 = self.connect() + if connected2 is True: + break + else: + continue if self.is_user_authorized(): self._check_events_pending_resolve()