Browse Source

Обработка ошибки подключения к серверу

Жирный грязный try excert
master
Дмитрий 3 years ago
parent
commit
42a9998b14
  1. 31
      solution.py

31
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:

Loading…
Cancel
Save