mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 19:03:46 +03:00
Handle AUTH_KEY_DUPLICATED on connection
This commit is contained in:
parent
2b9babb30f
commit
500792975e
|
@ -78,6 +78,9 @@ def rpc_message_to_error(code, message, report_method=None):
|
||||||
if code == 404:
|
if code == 404:
|
||||||
return NotFoundError(message)
|
return NotFoundError(message)
|
||||||
|
|
||||||
|
if code == 406:
|
||||||
|
return AuthKeyError(message)
|
||||||
|
|
||||||
if code == 500:
|
if code == 500:
|
||||||
return ServerError(message)
|
return ServerError(message)
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,19 @@ class NotFoundError(RPCError):
|
||||||
self.message = message
|
self.message = message
|
||||||
|
|
||||||
|
|
||||||
|
class AuthKeyError(RPCError):
|
||||||
|
"""
|
||||||
|
Errors related to invalid authorization key, like
|
||||||
|
AUTH_KEY_DUPLICATED which can cause the connection to fail.
|
||||||
|
"""
|
||||||
|
code = 406
|
||||||
|
message = 'AUTH_KEY'
|
||||||
|
|
||||||
|
def __init__(self, message):
|
||||||
|
super().__init__(message)
|
||||||
|
self.message = message
|
||||||
|
|
||||||
|
|
||||||
class FloodError(RPCError):
|
class FloodError(RPCError):
|
||||||
"""
|
"""
|
||||||
The maximum allowed number of attempts to invoke the given method
|
The maximum allowed number of attempts to invoke the given method
|
||||||
|
|
|
@ -11,7 +11,7 @@ from .crypto import rsa
|
||||||
from .errors import (
|
from .errors import (
|
||||||
RPCError, BrokenAuthKeyError, ServerError, FloodWaitError,
|
RPCError, BrokenAuthKeyError, ServerError, FloodWaitError,
|
||||||
FloodTestPhoneWaitError, TypeNotFoundError, UnauthorizedError,
|
FloodTestPhoneWaitError, TypeNotFoundError, UnauthorizedError,
|
||||||
PhoneMigrateError, NetworkMigrateError, UserMigrateError
|
PhoneMigrateError, NetworkMigrateError, UserMigrateError, AuthKeyError
|
||||||
)
|
)
|
||||||
from .network import authenticator, MtProtoSender, Connection, ConnectionMode
|
from .network import authenticator, MtProtoSender, Connection, ConnectionMode
|
||||||
from .sessions import Session, SQLiteSession
|
from .sessions import Session, SQLiteSession
|
||||||
|
@ -227,6 +227,15 @@ class TelegramBareClient:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
return self.connect(_sync_updates=_sync_updates)
|
return self.connect(_sync_updates=_sync_updates)
|
||||||
|
|
||||||
|
except AuthKeyError as e:
|
||||||
|
# As of late March 2018 there were two AUTH_KEY_DUPLICATED
|
||||||
|
# reports. Retrying with a clean auth_key should fix this.
|
||||||
|
__log__.warning('Auth key error %s. Clearing it and retrying.', e)
|
||||||
|
self.disconnect()
|
||||||
|
self.session.auth_key = None
|
||||||
|
self.session.save()
|
||||||
|
return self.connect(_sync_updates=_sync_updates)
|
||||||
|
|
||||||
except (RPCError, ConnectionError) as e:
|
except (RPCError, ConnectionError) as e:
|
||||||
# Probably errors from the previous session, ignore them
|
# Probably errors from the previous session, ignore them
|
||||||
__log__.error('Connection failed due to %s', e)
|
__log__.error('Connection failed due to %s', e)
|
||||||
|
|
|
@ -11,6 +11,7 @@ known_base_classes = {
|
||||||
401: 'UnauthorizedError',
|
401: 'UnauthorizedError',
|
||||||
403: 'ForbiddenError',
|
403: 'ForbiddenError',
|
||||||
404: 'NotFoundError',
|
404: 'NotFoundError',
|
||||||
|
406: 'AuthKeyError',
|
||||||
420: 'FloodError',
|
420: 'FloodError',
|
||||||
500: 'ServerError',
|
500: 'ServerError',
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user