22. Найти ошибки в коде асинхронных HTTP-запросов через aiohttp и asyncio.gather
Условие задачи Найти ошибки в коде ниже
import aiohttp
import asyncio
url = 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&explaintext&titles={title}'
Titles = ['Python', 'Dog', 'Cat']
async def make_req(session, title: str) -> dict:
async with session.get(url.format(title)) as response:
return await response.json()
async def main(titles: list = None):
async with aiohttp.ClientSession() as session:
tasks = [make_req(session, title) for title in Titles]
responses = asyncio.gather(*tasks)
for response in responses:
print(response)
await main(titles=Titles)