mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Raise FloodWaitError instead sleeping
This commit is contained in:
parent
7f84374e98
commit
63b1881c83
|
@ -44,6 +44,16 @@ class InvalidChecksumError(Exception):
|
||||||
self.valid_checksum = valid_checksum
|
self.valid_checksum = valid_checksum
|
||||||
|
|
||||||
|
|
||||||
|
class FloodWaitError(Exception):
|
||||||
|
def __init__(self, seconds):
|
||||||
|
super().__init__(
|
||||||
|
self,
|
||||||
|
'Too many requests were made too fast. Must wait {} seconds.'
|
||||||
|
.format(seconds)
|
||||||
|
)
|
||||||
|
self.seconds = seconds
|
||||||
|
|
||||||
|
|
||||||
class RPCError(Exception):
|
class RPCError(Exception):
|
||||||
|
|
||||||
CodeMessages = {
|
CodeMessages = {
|
||||||
|
|
|
@ -5,7 +5,7 @@ from time import sleep, time
|
||||||
|
|
||||||
from .. import helpers as utils
|
from .. import helpers as utils
|
||||||
from ..crypto import AES
|
from ..crypto import AES
|
||||||
from ..errors import (BadMessageError, RPCError,
|
from ..errors import (BadMessageError, FloodWaitError, RPCError,
|
||||||
InvalidDCError, ReadCancelledError)
|
InvalidDCError, ReadCancelledError)
|
||||||
from ..tl.all_tlobjects import tlobjects
|
from ..tl.all_tlobjects import tlobjects
|
||||||
from ..tl.functions import PingRequest
|
from ..tl.functions import PingRequest
|
||||||
|
@ -367,10 +367,7 @@ class MtProtoSender:
|
||||||
|
|
||||||
if error.message.startswith('FLOOD_WAIT_'):
|
if error.message.startswith('FLOOD_WAIT_'):
|
||||||
self.updates_thread_sleep = error.additional_data
|
self.updates_thread_sleep = error.additional_data
|
||||||
|
raise FloodWaitError(seconds=error.additional_data)
|
||||||
print('Should wait {}s. Sleeping until then.'.format(
|
|
||||||
error.additional_data))
|
|
||||||
sleep(error.additional_data)
|
|
||||||
|
|
||||||
elif '_MIGRATE_' in error.message:
|
elif '_MIGRATE_' in error.message:
|
||||||
raise InvalidDCError(error)
|
raise InvalidDCError(error)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user