mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-16 19:41:07 +03:00
Don't reset the auth_key upon receiving -404
This commit is contained in:
parent
f913ea6b75
commit
fdb0720fe9
|
@ -6,7 +6,7 @@ import re
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
ReadCancelledError, TypeNotFoundError, InvalidChecksumError,
|
ReadCancelledError, TypeNotFoundError, InvalidChecksumError,
|
||||||
InvalidBufferError, SecurityError, CdnFileTamperedError,
|
InvalidBufferError, AuthKeyNotFound, SecurityError, CdnFileTamperedError,
|
||||||
AlreadyInConversationError, BadMessageError, MultiError
|
AlreadyInConversationError, BadMessageError, MultiError
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"""Errors not related to the Telegram API itself"""
|
"""Errors not related to the Telegram API itself"""
|
||||||
import struct
|
import struct
|
||||||
|
import textwrap
|
||||||
|
|
||||||
from ..tl import TLRequest
|
from ..tl import TLRequest
|
||||||
|
|
||||||
|
@ -58,6 +59,22 @@ class InvalidBufferError(BufferError):
|
||||||
'Invalid response buffer (too short {})'.format(self.payload))
|
'Invalid response buffer (too short {})'.format(self.payload))
|
||||||
|
|
||||||
|
|
||||||
|
class AuthKeyNotFound(Exception):
|
||||||
|
"""
|
||||||
|
The server claims it doesn't know about the authorization key (session
|
||||||
|
file) currently being used. This might be because it either has never
|
||||||
|
seen this authorization key, or it used to know about the authorization
|
||||||
|
key but has forgotten it, either temporarily or permanently (possibly
|
||||||
|
due to server errors).
|
||||||
|
|
||||||
|
If the issue persists, you may need to recreate the session file and login
|
||||||
|
again. This is not done automatically because it is not possible to know
|
||||||
|
if the issue is temporary or permanent.
|
||||||
|
"""
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(textwrap.dedent(self.__class__.__doc__))
|
||||||
|
|
||||||
|
|
||||||
class SecurityError(Exception):
|
class SecurityError(Exception):
|
||||||
"""
|
"""
|
||||||
Generic security error, mostly used when generating a new AuthKey.
|
Generic security error, mostly used when generating a new AuthKey.
|
||||||
|
|
|
@ -10,7 +10,7 @@ from .mtprotostate import MTProtoState
|
||||||
from ..tl.tlobject import TLRequest
|
from ..tl.tlobject import TLRequest
|
||||||
from .. import helpers, utils
|
from .. import helpers, utils
|
||||||
from ..errors import (
|
from ..errors import (
|
||||||
BadMessageError, InvalidBufferError, SecurityError,
|
BadMessageError, InvalidBufferError, AuthKeyNotFound, SecurityError,
|
||||||
TypeNotFoundError, rpc_message_to_error
|
TypeNotFoundError, rpc_message_to_error
|
||||||
)
|
)
|
||||||
from ..extensions import BinaryReader
|
from ..extensions import BinaryReader
|
||||||
|
@ -377,11 +377,8 @@ class MTProtoSender:
|
||||||
except BufferError as e:
|
except BufferError as e:
|
||||||
# TODO there should probably only be one place to except all these errors
|
# TODO there should probably only be one place to except all these errors
|
||||||
if isinstance(e, InvalidBufferError) and e.code == 404:
|
if isinstance(e, InvalidBufferError) and e.code == 404:
|
||||||
self._log.info('Broken authorization key; resetting')
|
self._log.info('Server does not know about the current auth key; the session may need to be recreated')
|
||||||
self.auth_key.key = None
|
last_error = AuthKeyNotFound()
|
||||||
if self._auth_key_callback:
|
|
||||||
await self._auth_key_callback(None)
|
|
||||||
|
|
||||||
ok = False
|
ok = False
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -521,12 +518,8 @@ class MTProtoSender:
|
||||||
continue
|
continue
|
||||||
except BufferError as e:
|
except BufferError as e:
|
||||||
if isinstance(e, InvalidBufferError) and e.code == 404:
|
if isinstance(e, InvalidBufferError) and e.code == 404:
|
||||||
self._log.info('Broken authorization key; resetting')
|
self._log.info('Server does not know about the current auth key; the session may need to be recreated')
|
||||||
self.auth_key.key = None
|
await self._disconnect(error=AuthKeyNotFound())
|
||||||
if self._auth_key_callback:
|
|
||||||
await self._auth_key_callback(None)
|
|
||||||
|
|
||||||
await self._disconnect(error=e)
|
|
||||||
else:
|
else:
|
||||||
self._log.warning('Invalid buffer %s', e)
|
self._log.warning('Invalid buffer %s', e)
|
||||||
self._start_reconnect(e)
|
self._start_reconnect(e)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user