diff --git a/solution.py b/solution.py index 8810b32..28f3c76 100644 --- a/solution.py +++ b/solution.py @@ -100,20 +100,23 @@ async def send_async_request(cfg: Config, json_body: dict) -> None: url = cfg.central_host_url portion = cfg.request_portion - async with aiohttp.ClientSession(connector=conn) as session: - # получаем количесвто записей - count = await get_records_count(session, url) - - tasks = await get_tasks(f"{url}/get", portion, count, session, json_body) - - responses = await asyncio.gather(*tasks) - - # Пройдемся по ответам на запросы, запишем файлы конфига для - # каждого respone. Каждый response содержит portion или меньше хостов - for response in responses: - resp = await response.json() - hosts = [i["hostname"] for i in resp.get("result")] - await write_config_files(hosts, cfg, template) + try: + async with aiohttp.ClientSession(connector=conn) as session: + # получаем количесвто записей + count = await get_records_count(session, url) + + tasks = await get_tasks(f"{url}/get", portion, count, session, json_body) + + responses = await asyncio.gather(*tasks) + + # Пройдемся по ответам на запросы, запишем файлы конфига для + # каждого respone. Каждый response содержит portion или меньше хостов + for response in responses: + resp = await response.json() + hosts = [i["hostname"] for i in resp.get("result")] + await write_config_files(hosts, cfg, template) + except ClientConnectorError: + print(f"Невозможно подключиться к серверу {url}") def read_config(path_to_conf_file: str, section: str = "Main") -> Config: