mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Set requests timeout
This commit is contained in:
parent
b16963d4a9
commit
5466f0c342
3 changed files with 7 additions and 5 deletions
|
|
@ -55,7 +55,7 @@ async def check_result(method_name: str, content_type: str, status_code: int, bo
|
|||
:return: The result parsed to a JSON dictionary
|
||||
:raises ApiException: if one of the above listed cases is applicable
|
||||
"""
|
||||
log.debug(f"Response for {method_name}: [{status_code}] {body}")
|
||||
log.debug('Response for %s: [%d] "%r"', method_name, status_code, body)
|
||||
|
||||
if content_type != 'application/json':
|
||||
raise exceptions.NetworkError(f"Invalid response with content type {content_type}: \"{body}\"")
|
||||
|
|
@ -93,7 +93,9 @@ async def check_result(method_name: str, content_type: str, status_code: int, bo
|
|||
|
||||
|
||||
async def make_request(session, token, method, data=None, files=None, **kwargs):
|
||||
log.debug(f"Make request: '{method}' with data: {data} and files {files}")
|
||||
# log.debug(f"Make request: '{method}' with data: {data} and files {files}")
|
||||
log.debug('Make request: "%s" with data: "%r" and files "%r"', method, data, files)
|
||||
|
||||
url = Methods.api_url(token=token, method=method)
|
||||
|
||||
req = compose_data(data, files)
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class BaseBot:
|
|||
|
||||
async def request(self, method: base.String,
|
||||
data: Optional[Dict] = None,
|
||||
files: Optional[Dict] = None) -> Union[List, Dict, base.Boolean]:
|
||||
files: Optional[Dict] = None, **kwargs) -> Union[List, Dict, base.Boolean]:
|
||||
"""
|
||||
Make an request to Telegram Bot API
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ class BaseBot:
|
|||
:raise: :obj:`aiogram.exceptions.TelegramApiError`
|
||||
"""
|
||||
return await api.make_request(self.session, self.__token, method, data, files,
|
||||
proxy=self.proxy, proxy_auth=self.proxy_auth)
|
||||
proxy=self.proxy, proxy_auth=self.proxy_auth, **kwargs)
|
||||
|
||||
async def download_file(self, file_path: base.String,
|
||||
destination: Optional[base.InputFile] = None,
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class Bot(BaseBot):
|
|||
allowed_updates = prepare_arg(allowed_updates)
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
result = await self.request(api.Methods.GET_UPDATES, payload)
|
||||
result = await self.request(api.Methods.GET_UPDATES, payload, timeout=timeout + 2 if timeout else None)
|
||||
return [types.Update(**update) for update in result]
|
||||
|
||||
async def set_webhook(self, url: base.String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue