{"id":980,"hash":"2327268f55de5acd71720c156f10045f9eb83fcb2b274843133a66f8f4da5cae","pattern":"TypeError: An asyncio.Future, a coroutine or an awaitable is required","full_message":"I'm trying to make an asynchronous web scraper using beautifulsoup and aiohttp.This is my initial code to start things.I'm getting a [TypeError: An asyncio.Future, a coroutine or an awaitable is required] and having a hard time figuring out what is wrong with my code.I am new to python and would appreciate any help regarding this.\n\nimport bs4\nimport asyncio\nimport aiohttp\n\nasync def parse(page):\n    soup=bs4.BeautifulSoup(page,'html.parser')\n    soup.prettify()\n    print(soup.title)\n\nasync def request():\n    async with aiohttp.ClientSession() as session:\n        async with session.get(\"https://google.com\") as resp:\n            await parse(resp)\n\nloop=asyncio.get_event_loop()\nloop.run_until_complete(request)\n\nTraceback:-\n\nTraceback (most recent call last):\n  File \"C:\\Users\\User\\Desktop\\Bot\\aio-req\\parser.py\", line 21, in <module>\n    loop.run_until_complete(request)\n  File \"C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\asyncio\\base_events.py\", line 591, in run_until_complete\n    future = tasks.ensure_future(future, loop=self)\n  File \"C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\asyncio\\tasks.py\", line 673, in ensure_future\n    raise TypeError('An asyncio.Future, a coroutine or an awaitable is '\nTypeError: An asyncio.Future, a coroutine or an awaitable is required","ecosystem":"pypi","package_name":"python-3.x","package_version":null,"solution":"One issue is that loop.run_until_complete(request) should be loop.run_until_complete(request()) - You actually have to call it for it to return a coroutine.  \n\nThere are further problems - like you are passing an aiohttp.ClientResponse object to parse and treating it as text/html. I got it to work with the following but don't know if it fits your needs because  parse is no longer a coroutine.\n\ndef parse(page):\n    soup=bs4.BeautifulSoup(page,'html.parser')\n    soup.prettify()\n    return soup.title\n\nasync def fetch(session, url):\n    async with session.get(url) as response:\n        return await response.text()\n\nasync def request():\n    async with aiohttp.ClientSession() as session:\n        html = await fetch(session, \"https://google.com\")\n        print(parse(html))\n\nif __name__ == '__main__':\n    loop=asyncio.get_event_loop()\n    loop.run_until_complete(request())\n\nThis also works:\n\ndef parse(page):\n    soup=bs4.BeautifulSoup(page,'html.parser')\n    soup.prettify()\n    print(soup.title)\n\nasync def request():\n    async with aiohttp.ClientSession() as session:\n        async with session.get(\"https://google.com\") as resp:\n            parse(await resp.text())\n\nAnd finally, your original code, passing an awaitable response object to parse then awaiting for page.text().\n\nasync def parse(page):\n    soup=bs4.BeautifulSoup(await page.text(),'html.parser')\n    soup.prettify()\n    print(soup.title)\n\nasync def request():\n    async with aiohttp.ClientSession() as session:\n        async with session.get(\"https://google.com\") as resp:\n            await parse(resp)","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/59481105/typeerror-an-asyncio-future-a-coroutine-or-an-awaitable-is-required","votes":18,"created_at":"2026-04-19T04:52:07.354035+00:00","updated_at":"2026-04-19T04:52:07.354035+00:00"}