Raise FloodWaitError instead sleeping

This commit is contained in:
Lonami Exo 2017-05-29 16:46:17 +02:00
parent 7f84374e98
commit 63b1881c83
2 changed files with 12 additions and 5 deletions

View File

@ -44,6 +44,16 @@ class InvalidChecksumError(Exception):
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):
CodeMessages = {

View File

@ -5,7 +5,7 @@ from time import sleep, time
from .. import helpers as utils
from ..crypto import AES
from ..errors import (BadMessageError, RPCError,
from ..errors import (BadMessageError, FloodWaitError, RPCError,
InvalidDCError, ReadCancelledError)
from ..tl.all_tlobjects import tlobjects
from ..tl.functions import PingRequest
@ -367,10 +367,7 @@ class MtProtoSender:
if error.message.startswith('FLOOD_WAIT_'):
self.updates_thread_sleep = error.additional_data
print('Should wait {}s. Sleeping until then.'.format(
error.additional_data))
sleep(error.additional_data)
raise FloodWaitError(seconds=error.additional_data)
elif '_MIGRATE_' in error.message:
raise InvalidDCError(error)