Respect RetryAfter with polling Updater

This commit is contained in:
Noam Meltzer 2016-10-15 23:38:11 +03:00
parent de96cc87ea
commit a68cf8d464
2 changed files with 5 additions and 2 deletions

View file

@ -110,4 +110,4 @@ class RetryAfter(TelegramError):
"""
super(RetryAfter,
self).__init__('Flood control exceeded. Retry in {} seconds'.format(retry_after))
self.retry_after = retry_after
self.retry_after = float(retry_after)

View file

@ -30,7 +30,7 @@ from queue import Queue
from telegram import Bot, TelegramError
from telegram.ext import Dispatcher, JobQueue
from telegram.error import Unauthorized, InvalidToken
from telegram.error import Unauthorized, InvalidToken, RetryAfter
from telegram.utils.request import Request
from telegram.utils.webhookhandler import (WebhookServer, WebhookHandler)
@ -233,6 +233,9 @@ class Updater(object):
try:
updates = self.bot.getUpdates(
self.last_update_id, timeout=timeout, network_delay=network_delay)
except RetryAfter as e:
self.logger.info(str(e))
cur_interval = 0.5 + e.retry_after
except TelegramError as te:
self.logger.error("Error while getting Updates: {0}".format(te))