Xiao Poor
Xiao Poor

Reputation: 35

Async-await was never awaited in function call

When I try to call the function 'check', it couldn't be called and run into an error.

RuntimeWarning: coroutine 'Acc.check' was never awaited

import json, random

# -- Functions --
async def read():
    with open("data.json", "r") as f:
        data = json.load(f)

# -- Commands --
class Acc:
    async def check():
        data = await read()

        user = data.keys()

        if str(user) not in data:
            numbers = "012345689"
            
            user = "".join(random.sample(numbers, 8))

            data[str(user)] = {}

            with open("data.json", "w") as f:
                json.dump(data, f, indent=4)

Acc.check()

Upvotes: 0

Views: 144

Answers (1)

itismoej
itismoej

Reputation: 1847

The Acc.check() returns a coroutine object. You should run it in an event-loop:

import asyncio

# your codes
...

asyncio.run(Acc.check())

Upvotes: 2

Related Questions