Ask coding questions

← Back to all posts
FIXED Asynchronous OOP HTTP requests Python

I'm trying to make a class to interact with a database server (which I have already written and works), but I do not know enough about async programming to understand why I am getting this error, so help would be appreciated.
It runs better from a synchronous context, with

which creates the client and gets as far as run and then makeRequest, before raising RuntimeError: Event loop is closed when it tries to make the actual request (async with, json = data) as req in makeRequest),
however in an async context

it raises multiple errors, (RuntimeError: cannot be called from a running event loop and UnboundLocalError: local variable 'client' referenced before assignment).
This is less than ideal, as eventually I am intending to use it from an asynchronous context (a discord bot)
Also if anybody has any suggestions about the todo on line 105 that would be useful


Fixed with nest-asyncio package, added

to the top of