mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-03 10:45:52 +03:00
Catch -404 BrokenAuthKeyError on .connect()'s .do_authentication
This commit is contained in:
parent
940dfe6816
commit
e7a936222f
|
@ -3,7 +3,7 @@ import re
|
|||
|
||||
from .common import (
|
||||
ReadCancelledError, InvalidParameterError, TypeNotFoundError,
|
||||
InvalidChecksumError, CdnFileTamperedError
|
||||
InvalidChecksumError, BrokenAuthKeyError, CdnFileTamperedError
|
||||
)
|
||||
|
||||
from .rpc_errors import (
|
||||
|
|
|
@ -38,6 +38,14 @@ class InvalidChecksumError(Exception):
|
|||
self.valid_checksum = valid_checksum
|
||||
|
||||
|
||||
class BrokenAuthKeyError(Exception):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
self,
|
||||
'The authorization key is broken, and it must be reset.'
|
||||
)
|
||||
|
||||
|
||||
class CdnFileTamperedError(Exception):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import time
|
||||
|
||||
from ..errors import BrokenAuthKeyError
|
||||
from ..extensions import BinaryReader, BinaryWriter
|
||||
|
||||
|
||||
|
@ -36,6 +37,10 @@ class MtProtoPlainSender:
|
|||
def receive(self):
|
||||
"""Receives a plain packet, returning the body of the response"""
|
||||
body = self._connection.recv()
|
||||
if body == b'l\xfe\xff\xff': # -404 little endian signed
|
||||
# Broken authorization, must reset the auth key
|
||||
raise BrokenAuthKeyError()
|
||||
|
||||
with BinaryReader(body) as reader:
|
||||
reader.read_long() # auth_key_id
|
||||
reader.read_long() # msg_id
|
||||
|
|
|
@ -7,13 +7,14 @@ from os import path
|
|||
from . import helpers as utils
|
||||
from .crypto import rsa, CdnDecrypter
|
||||
from .errors import (
|
||||
RPCError, FloodWaitError, FileMigrateError, TypeNotFoundError
|
||||
RPCError, BrokenAuthKeyError,
|
||||
FloodWaitError, FileMigrateError, TypeNotFoundError
|
||||
)
|
||||
from .network import authenticator, MtProtoSender, Connection, ConnectionMode
|
||||
from .tl import TLObject, Session
|
||||
from .tl.all_tlobjects import LAYER
|
||||
from .tl.functions import (
|
||||
InitConnectionRequest, InvokeWithLayerRequest, PingRequest
|
||||
InitConnectionRequest, InvokeWithLayerRequest
|
||||
)
|
||||
from .tl.functions.auth import (
|
||||
ImportAuthorizationRequest, ExportAuthorizationRequest
|
||||
|
@ -115,8 +116,11 @@ class TelegramBareClient:
|
|||
if not self.session.auth_key:
|
||||
# New key, we need to tell the server we're going to use
|
||||
# the latest layer
|
||||
self.session.auth_key, self.session.time_offset = \
|
||||
authenticator.do_authentication(connection)
|
||||
try:
|
||||
self.session.auth_key, self.session.time_offset = \
|
||||
authenticator.do_authentication(connection)
|
||||
except BrokenAuthKeyError:
|
||||
return False
|
||||
|
||||
self.session.layer = LAYER
|
||||
self.session.save()
|
||||
|
|
Loading…
Reference in New Issue
Block a user