mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Fix asyncio_helper.py
This commit is contained in:
parent
b3b318fd28
commit
e7d0ec1f6c
@ -39,7 +39,7 @@ MAX_RETRIES = 3
|
|||||||
logger = telebot.logger
|
logger = telebot.logger
|
||||||
|
|
||||||
async def _process_request(token, url, method='get', params=None, files=None, request_timeout=None):
|
async def _process_request(token, url, method='get', params=None, files=None, request_timeout=None):
|
||||||
params = compose_data(params, files)
|
params = prepare_data(params, files)
|
||||||
if request_timeout is None:
|
if request_timeout is None:
|
||||||
request_timeout = REQUEST_TIMEOUT
|
request_timeout = REQUEST_TIMEOUT
|
||||||
timeout = aiohttp.ClientTimeout(total=request_timeout)
|
timeout = aiohttp.ClientTimeout(total=request_timeout)
|
||||||
@ -54,6 +54,8 @@ async def _process_request(token, url, method='get', params=None, files=None, re
|
|||||||
json_result = await _check_result(url, response)
|
json_result = await _check_result(url, response)
|
||||||
if json_result:
|
if json_result:
|
||||||
return json_result['result']
|
return json_result['result']
|
||||||
|
except (ApiTelegramException,ApiInvalidJSONException, ApiHTTPException) as e:
|
||||||
|
raise e
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if not got_result:
|
if not got_result:
|
||||||
@ -62,9 +64,9 @@ async def _process_request(token, url, method='get', params=None, files=None, re
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def guess_filename(obj):
|
def prepare_file(obj):
|
||||||
"""
|
"""
|
||||||
Get file name from object
|
returns os.path.basename for a given file
|
||||||
|
|
||||||
:param obj:
|
:param obj:
|
||||||
:return:
|
:return:
|
||||||
@ -74,9 +76,9 @@ def guess_filename(obj):
|
|||||||
return os.path.basename(name)
|
return os.path.basename(name)
|
||||||
|
|
||||||
|
|
||||||
def compose_data(params=None, files=None):
|
def prepare_data(params=None, files=None):
|
||||||
"""
|
"""
|
||||||
Prepare request data
|
prepare data for request.
|
||||||
|
|
||||||
:param params:
|
:param params:
|
||||||
:param files:
|
:param files:
|
||||||
@ -96,7 +98,7 @@ def compose_data(params=None, files=None):
|
|||||||
else:
|
else:
|
||||||
raise ValueError('Tuple must have exactly 2 elements: filename, fileobj')
|
raise ValueError('Tuple must have exactly 2 elements: filename, fileobj')
|
||||||
else:
|
else:
|
||||||
filename, fileobj = guess_filename(f) or key, f
|
filename, fileobj = prepare_file(f) or key, f
|
||||||
|
|
||||||
data.add_field(key, fileobj, filename=filename)
|
data.add_field(key, fileobj, filename=filename)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user