mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Add connect timeout. Fix #108
This commit is contained in:
parent
c1247249c7
commit
209764a5d7
@ -10,6 +10,9 @@ logger = telebot.logger
|
|||||||
API_URL = "https://api.telegram.org/bot{0}/{1}"
|
API_URL = "https://api.telegram.org/bot{0}/{1}"
|
||||||
FILE_URL = "https://api.telegram.org/file/bot{0}/{1}"
|
FILE_URL = "https://api.telegram.org/file/bot{0}/{1}"
|
||||||
|
|
||||||
|
CONNECT_TIMEOUT = 3.5
|
||||||
|
READ_TIMEOUT = 9999
|
||||||
|
|
||||||
|
|
||||||
def _make_request(token, method_name, method='get', params=None, files=None, base_url=API_URL):
|
def _make_request(token, method_name, method='get', params=None, files=None, base_url=API_URL):
|
||||||
"""
|
"""
|
||||||
@ -23,7 +26,10 @@ def _make_request(token, method_name, method='get', params=None, files=None, bas
|
|||||||
"""
|
"""
|
||||||
request_url = base_url.format(token, method_name)
|
request_url = base_url.format(token, method_name)
|
||||||
logger.debug("Request: method={0} url={1} params={2} files={3}".format(method, request_url, params, files))
|
logger.debug("Request: method={0} url={1} params={2} files={3}".format(method, request_url, params, files))
|
||||||
result = requests.request(method, request_url, params=params, files=files)
|
read_timeout = READ_TIMEOUT
|
||||||
|
if params:
|
||||||
|
if 'timeout' in params: read_timeout = params['timeout'] + 10
|
||||||
|
result = requests.request(method, request_url, params=params, files=files, timeout=(CONNECT_TIMEOUT, read_timeout))
|
||||||
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
|
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
|
||||||
return _check_result(method_name, result)['result']
|
return _check_result(method_name, result)['result']
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user