I'm aware of python asyncio - RuntimeError: await wasn't used with future, however the answer there doesn't address what went on here.
When using aiohttp
I ran across the following error:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/selector_events.py", line 485, in sock_connect
return await fut
RuntimeError: await wasn't used with future
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fb28040f760>
Here is the code associated:
urls = # some list of URLs including `https://www.alphavantage.co/query?function=OVERVIEW&symbol=IBM&apikey=demo`.....
async def run_tasks():
session = aiohttp.ClientSession()
tasks = [session.get(url) for url in urls]
await asyncio.gather(*tasks)
await session.close()
asyncio.run(run_tasks())
It looks like I am awaiting the event loop properly, but I keep hitting this issue, what gives?
Versions:
aiohttp==3.7.4.post0
asyncio==3.4.3
Python 3.8.0
There are 2 things that could be happening here:
await
ing something that you should beAccording to the aiohttp documentation
By default aiohttp uses strict checks for HTTPS protocol. Certification checks can be relaxed by setting ssl to False
So it's likely that the urls
that you're using are hitting this threshold, and you're getting kicked out. Change the line:
tasks = [session.get(url) for url in urls]
to
tasks = [session.get(url, ssl=False) for url in urls]