|
44 | 44 | PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded, |
45 | 45 | PasswordHashInvalid, FloodWait, PeerIdInvalid, FirstnameInvalid, PhoneNumberBanned, |
46 | 46 | VolumeLocNotFound, UserMigrate, ChannelPrivate, PhoneNumberOccupied, |
47 | | - PasswordRecoveryNa, PasswordEmpty |
| 47 | + PasswordRecoveryNa, PasswordEmpty, AuthBytesInvalid |
48 | 48 | ) |
49 | 49 | from pyrogram.session import Auth, Session |
50 | 50 | from .ext import utils, Syncer, BaseClient, Dispatcher |
@@ -1238,7 +1238,7 @@ async def send(self, |
1238 | 1238 | def load_config(self): |
1239 | 1239 | parser = ConfigParser() |
1240 | 1240 | parser.read(str(self.config_file)) |
1241 | | - |
| 1241 | + |
1242 | 1242 | if self.bot_token: |
1243 | 1243 | pass |
1244 | 1244 | else: |
@@ -1322,7 +1322,7 @@ async def load_session(self): |
1322 | 1322 | ]) |
1323 | 1323 |
|
1324 | 1324 | if session_empty: |
1325 | | - self.storage.dc_id = 4 |
| 1325 | + self.storage.dc_id = 2 |
1326 | 1326 | self.storage.date = 0 |
1327 | 1327 |
|
1328 | 1328 | self.storage.test_mode = self.test_mode |
@@ -1745,33 +1745,35 @@ async def get_file(self, media_type: int, |
1745 | 1745 |
|
1746 | 1746 | if session is None: |
1747 | 1747 | if dc_id != self.storage.dc_id: |
1748 | | - exported_auth = await self.send( |
1749 | | - functions.auth.ExportAuthorization( |
1750 | | - dc_id=dc_id |
1751 | | - ) |
1752 | | - ) |
1753 | | - |
1754 | | - session = Session( |
1755 | | - self, |
1756 | | - dc_id, |
1757 | | - await Auth(self, dc_id).create(), is_media=True) |
1758 | | - |
| 1748 | + session = Session(self, dc_id, await Auth(self, dc_id).create(), is_media=True) |
1759 | 1749 | await session.start() |
1760 | 1750 |
|
1761 | | - self.media_sessions[dc_id] = session |
1762 | | - |
1763 | | - await session.send( |
1764 | | - functions.auth.ImportAuthorization( |
1765 | | - id=exported_auth.id, |
1766 | | - bytes=exported_auth.bytes |
| 1751 | + for _ in range(3): |
| 1752 | + exported_auth = await self.send( |
| 1753 | + functions.auth.ExportAuthorization( |
| 1754 | + dc_id=dc_id |
| 1755 | + ) |
1767 | 1756 | ) |
1768 | | - ) |
| 1757 | + |
| 1758 | + try: |
| 1759 | + await session.send( |
| 1760 | + functions.auth.ImportAuthorization( |
| 1761 | + id=exported_auth.id, |
| 1762 | + bytes=exported_auth.bytes |
| 1763 | + ) |
| 1764 | + ) |
| 1765 | + except AuthBytesInvalid: |
| 1766 | + continue |
| 1767 | + else: |
| 1768 | + break |
| 1769 | + else: |
| 1770 | + await session.stop() |
| 1771 | + raise AuthBytesInvalid |
1769 | 1772 | else: |
1770 | 1773 | session = Session(self, dc_id, self.storage.auth_key, is_media=True) |
1771 | | - |
1772 | 1774 | await session.start() |
1773 | 1775 |
|
1774 | | - self.media_sessions[dc_id] = session |
| 1776 | + self.media_sessions[dc_id] = session |
1775 | 1777 |
|
1776 | 1778 | if media_type == 1: |
1777 | 1779 | location = types.InputPeerPhotoFileLocation( |
|
0 commit comments