'FASTAPI > Heroku Error: RuntimeError: Task <Task pending name='Task-6' coro=<RequestResponseCycle.run_asgi() running at /app/.heroku/

I was trying to Deploy my REST API built on FastAPI I'm using Motor for establishing connection with my MongoDB

I hosted the app on Heroku but now I'm getting the follow error:

2022-03-25T06:11:43.470304+00:00 app[web.1]:     async for document in cursor:
2022-03-25T06:11:43.470304+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/motor/core.py", line 1158, in next
2022-03-25T06:11:43.470304+00:00 app[web.1]:     if self.alive and (self._buffer_size() or await self._get_more()):
2022-03-25T06:11:43.470305+00:00 app[web.1]: RuntimeError: Task <Task pending name='Task-6' coro=<RequestResponseCycle.run_asgi() running at /app/.heroku/python/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py:366> cb=[set.discard()]> got Future <Future pending cb=[_chain_future.<locals>._call_check_cancel() at /app/.heroku/python/lib/python3.10/asyncio/futures.py:384]> attached to a different loop

Here's the Code from Line 11 to 16

async def get_all_APIs():
    apis = []
    cursor = Collection.find({})
    async for document in cursor:
        apis.append(APIData(**document))
    return apis

I was trying to deploy fastapi on Heroku but got an error



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source