diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index 9696d60c..2846bed6 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -312,16 +312,11 @@ class TelegramBaseClient(abc.ABC): self.session.server_address, self.session.port, loop=self._loop, proxy=self._proxy )) + self.session.auth_key = self._sender.auth_key await self._sender.send(self._init_with( functions.help.GetConfigRequest())) - # AuthKey is a property, so re-setting it has side-effects. - # Since it's used as a reference and only its inner payload - # may have actually changed after connecting, we use the - # reference from the session file itself as its value. - self.session.auth_key = self.session.auth_key - self._updates_handle = self._loop.create_task(self._update_loop()) def is_connected(self): diff --git a/telethon/network/mtprotosender.py b/telethon/network/mtprotosender.py index b4347586..28a2da8e 100644 --- a/telethon/network/mtprotosender.py +++ b/telethon/network/mtprotosender.py @@ -68,8 +68,8 @@ class MTProtoSender: self._recv_loop_handle = None # Preserving the references of the AuthKey and state is important - self._auth_key = auth_key or AuthKey(None) - self._state = MTProtoState(self._auth_key) + self.auth_key = auth_key or AuthKey(None) + self._state = MTProtoState(self.auth_key) # Outgoing messages are put in a queue and sent in a batch. # Note that here we're also storing their ``_RequestState``. @@ -204,12 +204,12 @@ class MTProtoSender: .format(self._retries)) __log__.debug('Connection success!') - if not self._auth_key: + if not self.auth_key: plain = MTProtoPlainSender(self._connection) for retry in range(1, self._retries + 1): try: __log__.debug('New auth_key attempt {}...'.format(retry)) - self._auth_key.key, self._state.time_offset =\ + self.auth_key.key, self._state.time_offset =\ await authenticator.do_authentication(plain) break @@ -402,7 +402,7 @@ class MTProtoSender: else: __log__.warning('Invalid buffer %s', e) - self._auth_key.key = None + self.auth_key.key = None self._start_reconnect() return except Exception: