From a68cf8d464e5114582e299a3a0b95c3eaef6ebe8 Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Sat, 15 Oct 2016 23:38:11 +0300 Subject: [PATCH] Respect RetryAfter with polling Updater --- telegram/error.py | 2 +- telegram/ext/updater.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/telegram/error.py b/telegram/error.py index cdfc4fa9f..8ca6a60cf 100644 --- a/telegram/error.py +++ b/telegram/error.py @@ -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) diff --git a/telegram/ext/updater.py b/telegram/ext/updater.py index 2a7707ae0..e20f40387 100644 --- a/telegram/ext/updater.py +++ b/telegram/ext/updater.py @@ -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))