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 url = cfg.central_host_url
portion = cfg.request_portion portion = cfg.request_portion
async with aiohttp.ClientSession(connector=conn) as session: try:
# получаем количесвто записей async with aiohttp.ClientSession(connector=conn) as session:
count = await get_records_count(session, url) # получаем количесвто записей
count = await get_records_count(session, url)
tasks = await get_tasks(f"{url}/get", portion, count, session, json_body)
tasks = await get_tasks(f"{url}/get", portion, count, session, json_body)
responses = await asyncio.gather(*tasks)
responses = await asyncio.gather(*tasks)
# Пройдемся по ответам на запросы, запишем файлы конфига для
# каждого respone. Каждый response содержит portion или меньше хостов # Пройдемся по ответам на запросы, запишем файлы конфига для
for response in responses: # каждого respone. Каждый response содержит portion или меньше хостов
resp = await response.json() for response in responses:
hosts = [i["hostname"] for i in resp.get("result")] resp = await response.json()
await write_config_files(hosts, cfg, template) 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: def read_config(path_to_conf_file: str, section: str = "Main") -> Config:

Loading…
Cancel
Save