From 5ac71baafed01bd7fa65eea7b101260134b8b6ae Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sun, 7 Nov 2021 23:02:23 +0300 Subject: [PATCH] RETRY_ENGINE Added RETRY_ENGINE var to api_helper. Added RETRY_ENGINE = 2 based on native "requests" retry mechanism. --- telebot/apihelper.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index e9162ce..e236723 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -9,6 +9,7 @@ except ImportError: import requests from requests.exceptions import HTTPError, ConnectionError, Timeout +from requests.adapters import HTTPAdapter try: # noinspection PyUnresolvedReferences @@ -38,6 +39,7 @@ SESSION_TIME_TO_LIVE = 600 # In seconds. None - live forever, 0 - one-time RETRY_ON_ERROR = False RETRY_TIMEOUT = 2 MAX_RETRIES = 15 +RETRY_ENGINE = 1 CUSTOM_SERIALIZER = None CUSTOM_REQUEST_SENDER = None @@ -107,45 +109,48 @@ def _make_request(token, method_name, method='get', params=None, files=None): params = params or None # Set params to None if empty result = None - if RETRY_ON_ERROR: + if RETRY_ON_ERROR and RETRY_ENGINE == 1: got_result = False current_try = 0 - while not got_result and current_try