scenarios when using aiohttp with async context manager in Python 3.10 for REST API calls
I need help solving Hey everyone, I'm running into an issue that's driving me crazy... I'm stuck on something that should probably be simple. I'm trying to use `aiohttp` to make asynchronous REST API calls in my Python 3.10 application. I want to ensure that sessions are properly closed after use, so I'm utilizing the async context manager. However, I'm working with a `RuntimeError: Task <Task pending name='Task-1' coro=<ClientSession.get() done, defined at ...> cb=[_run_until_complete_cb() at /usr/lib/python3.10/asyncio/base_events.py:184]> was never awaited` behavior when I run my code. Here's a simplified version of what I'm doing: ```python import aiohttp import asyncio async def fetch_data(url): async with aiohttp.ClientSession() as session: async with session.get(url) as response: return await response.json() async def main(): url = 'https://api.example.com/data' data = await fetch_data(url) print(data) if __name__ == '__main__': asyncio.run(main()) ``` I've ensured that I'm using `asyncio.run()` correctly, yet it seems like the async call within `fetch_data` is not awaited properly. I've also checked that all libraries are updated to their latest versions. The strange part is that when I remove the `async with session.get(url)`, the behavior goes away, but then I need to handle the response correctly. Is there something I'm missing here? Any suggestions would be appreciated! For context: I'm using Python 3.10 on Windows. Any ideas what could be causing this? Thanks in advance! I'm on macOS using the latest version of Python 3.10. I appreciate any insights!