iojw / socialscan

Python library for accurately querying username and email usage on online platforms
Mozilla Public License 2.0
1.48k stars 185 forks source link

RuntimeWarning: coroutine 'execute_queries' was never awaited #36

Closed beucismis closed 3 years ago

beucismis commented 3 years ago

Hello, I'm writing a Discord bot command.

@commands.command(aliases=["sscan"])
async def socialscan(self, ctx, account):
    results = sync_execute_queries([account], config.PLATFORMS)

    embed = discord.Embed()
    embed.description = "\n".join(
        [
            "{} on {}: `{} (Success: {}, Valid: {}, Available: {})`".format(
                r.query,
                r.platform,
                r.message,
                r.success,
                r.valid,
                r.available,
            )
            for r in results
        ]
    )

    await ctx.send(embed=embed)

Error message:

In socialscan:
  File "/home/adil/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 114, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/adil/Projects/ymybot-rw/cogs/api.py", line 24, in socialscan
    results = sync_execute_queries(accounts, config.PLATFORMS)
  File "/usr/local/lib/python3.9/dist-packages/socialscan/util.py", line 85, in sync_execute_queries
    return asyncio.run(execute_queries(queries, platforms, proxy_list))
  File "/usr/lib/python3.9/asyncio/runners.py", line 33, in run
    raise RuntimeError(
RuntimeError: asyncio.run() cannot be called from a running event loop
/usr/lib/python3.9/asyncio/events.py:80: RuntimeWarning: coroutine 'execute_queries' was never awaited
  self._context.run(self._callback, *self._args)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
iojw commented 3 years ago

Since you're calling it from inside an async function, you probably want to use the async execute_queries function instead:

results = await execute_queries(accounts, config.PLATFORMS)

sync_execute_queries is just a wrapper around execute_queries.

beucismis commented 3 years ago

Thank you.