From a332d29c4c7efff98ca890c2ba3d818f361a5040 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 22 Jul 2018 00:40:39 +0200 Subject: [PATCH] Fix-up 5a9a00e to handle exporting senders to the same DC --- telethon/client/downloads.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/telethon/client/downloads.py b/telethon/client/downloads.py index e2f1a382..e0197241 100644 --- a/telethon/client/downloads.py +++ b/telethon/client/downloads.py @@ -203,7 +203,20 @@ class DownloadMethods(UserMethods): dc_id, input_location = utils.get_input_location(input_location) exported = dc_id and self.session.dc_id != dc_id if exported: - sender = await self._borrow_exported_sender(dc_id) + try: + sender = await self._borrow_exported_sender(dc_id) + except errors.DcIdInvalidError: + # Can't export a sender for the ID we are currently in + config = await self(functions.help.GetConfigRequest()) + for option in config.dc_options: + if option.ip_address == self.session.server_address: + self.session.set_dc( + option.id, option.ip_address, option.port) + self.session.save() + break + + # TODO Figure out why the session may have the wrong DC ID + sender = self._sender else: # The used sender will also change if ``FileMigrateError`` occurs sender = self._sender