mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 01:16:35 +03:00
Fix disconnect and reconnect for exported senders (#53)
This commit is contained in:
parent
097d1669b2
commit
6b4f2abb96
|
@ -51,7 +51,11 @@ class InteractiveTelegramClient(TelegramClient):
|
|||
self.found_media = set()
|
||||
|
||||
print('Connecting to Telegram servers...')
|
||||
self.connect()
|
||||
if not self.connect():
|
||||
print('Initial connection failed. Retrying...')
|
||||
if not self.connect():
|
||||
print('Could not connect to Telegram servers.')
|
||||
return
|
||||
|
||||
# Then, ensure we're authorized and have access
|
||||
if not self.is_user_authorized():
|
||||
|
|
|
@ -147,7 +147,8 @@ class TelegramClient:
|
|||
self._setup_ping_thread()
|
||||
|
||||
return True
|
||||
except RPCError as error:
|
||||
except (RPCError, ConnectionError) as error:
|
||||
# Probably errors from the previous session, ignore them
|
||||
self._logger.warning('Could not stabilise initial connection: {}'
|
||||
.format(error))
|
||||
return False
|
||||
|
@ -163,7 +164,7 @@ class TelegramClient:
|
|||
self.transport = None
|
||||
|
||||
# Also disconnect all the cached senders
|
||||
for sender in self._cached_senders:
|
||||
for sender in self._cached_senders.values():
|
||||
sender.disconnect()
|
||||
|
||||
self._cached_senders.clear()
|
||||
|
@ -196,7 +197,7 @@ class TelegramClient:
|
|||
if not self.dc_options:
|
||||
raise ConnectionError(
|
||||
'Cannot determine the required data center IP address. '
|
||||
'Stabilise an initial connection first.')
|
||||
'Stabilise a successful initial connection first.')
|
||||
|
||||
return next(dc for dc in self.dc_options if dc.id == dc_id)
|
||||
|
||||
|
@ -218,8 +219,8 @@ class TelegramClient:
|
|||
|
||||
if sender and session:
|
||||
if init_connection:
|
||||
# TODO reconnect
|
||||
pass
|
||||
sender.disconnect()
|
||||
sender.connect()
|
||||
|
||||
return sender
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user