I just got into trying to make a bot using the AsyncPraw Reddit API wrapper. I copy-pasted the code example in the documentation and i can't get it to run without getting atleast a warning.
by trying to execute this code:
import asyncpraw
import asyncio
import auth
from time import sleep
async def amain():
reddit = asyncpraw.Reddit(
client_id=auth.CLIENT_ID,
client_secret=auth.CLIENT_SECRET,
user_agent="Example bot",
password=auth.PASSWORD,
username=auth.USERNAME,
ratelimit_seconds=700
)
print(reddit.read_only)
# Output: True
# continued from code above
subreddit = await reddit.subreddit("askreddit")
async for submission in subreddit.top(limit=10):
print(submission.title)
asyncio.run(amain())
Everything works, the submission titles get printed, but then, this happens:
> Unclosed client session client_session: <aiohttp.client.ClientSession
> object at 0x000001D53CA8D6C0> Unclosed connector connections:
> ['[(<aiohttp.client_proto.ResponseHandler object at
> 0x000001D53C246FE0>, 116575.906)]'] connector:
> <aiohttp.connector.TCPConnector object at 0x000001D53CA8D7E0> Fatal
> error on SSL transport protocol: <asyncio.sslproto.SSLProtocol object
> at 0x000001D53CA8EB30> transport: <_ProactorSocketTransport fd=-1
> read=<_OverlappedFuture cancelled>>
...
> RuntimeError: Event loop is closed
tried to fix by replacing the asyncio.run(amain())
with:
loop = asyncio.get_event_loop()
loop.run_until_complete(amain())
and this fixes the RuntimeError: Event loop is closed
, but the Unclosed client session client_session: <aiohttp.client.ClientSession
. and all the things that follow it remain.
and on top of that, now i get a
DeprecationWarning: There is no current event loop loop = asyncio.get_event_loop()