From 1d159908c731a7525bc51f46faa455884fcb382e Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 1 Oct 2017 11:25:56 +0200 Subject: [PATCH] Fix RPC excepts (e.g. UserMigrate) being in the wrong try --- telethon/telegram_bare_client.py | 50 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/telethon/telegram_bare_client.py b/telethon/telegram_bare_client.py index b672c842..d41a8b8e 100644 --- a/telethon/telegram_bare_client.py +++ b/telethon/telegram_bare_client.py @@ -463,20 +463,6 @@ class TelegramBareClient: while not all(x.confirm_received.is_set() for x in requests): sender.receive(update_state=self.updates) - except (PhoneMigrateError, NetworkMigrateError, - UserMigrateError) as e: - self._logger.debug( - 'DC error when invoking request, ' - 'attempting to reconnect at DC {}'.format(e.new_dc) - ) - - # TODO What happens with the background thread here? - # For normal use cases, this won't happen, because this will only - # be on the very first connection (not authorized, not running), - # but may be an issue for people who actually travel? - self._reconnect(new_dc=e.new_dc) - return self._invoke(sender, call_receive, *requests) - except TimeoutError: pass # We will just retry @@ -496,17 +482,6 @@ class TelegramBareClient: while self._user_connected and not self._reconnect(): sleep(0.1) # Retry forever until we can send the request - except ServerError as e: - # Telegram is having some issues, just retry - self._logger.debug( - '[ERROR] Telegram is having some internal issues', e - ) - - except FloodWaitError: - sender.disconnect() - self.disconnect() - raise - finally: if sender != self._sender: sender.disconnect() @@ -523,6 +498,31 @@ class TelegramBareClient: else: return [x.result for x in requests] + except (PhoneMigrateError, NetworkMigrateError, + UserMigrateError) as e: + self._logger.debug( + 'DC error when invoking request, ' + 'attempting to reconnect at DC {}'.format(e.new_dc) + ) + + # TODO What happens with the background thread here? + # For normal use cases, this won't happen, because this will only + # be on the very first connection (not authorized, not running), + # but may be an issue for people who actually travel? + self._reconnect(new_dc=e.new_dc) + return self._invoke(sender, call_receive, *requests) + + except ServerError as e: + # Telegram is having some issues, just retry + self._logger.debug( + '[ERROR] Telegram is having some internal issues', e + ) + + except FloodWaitError: + sender.disconnect() + self.disconnect() + raise + # Let people use client(SomeRequest()) instead client.invoke(...) __call__ = invoke