Top-gg-Community / python-sdk

A simple API wrapper for top.gg written in Python
https://docs.top.gg/docs/Libraries/python
MIT License
91 stars 54 forks source link

TypeError: object Lock can't be used in 'await' expression #35

Closed Breee closed 3 years ago

Breee commented 3 years ago

Exception:

pokemon_raidquaza | Unclosed client session
pokemon_raidquaza | client_session: <aiohttp.client.ClientSession object at 0x7fa33c6409d0>
pokemon_raidquaza | Task exception was never retrieved
pokemon_raidquaza | future: <Task finished name='Task-1' coro=<DBLClient._auto_post() done, defined at /usr/local/lib/python3.9/site-packages/dbl/client.py:110> exception=TypeError("object Lock can't be used in 'await' expression")>
pokemon_raidquaza | Traceback (most recent call last):
pokemon_raidquaza |   File "/usr/local/lib/python3.9/site-packages/dbl/client.py", line 114, in _auto_post
pokemon_raidquaza |     await self.post_guild_count()
pokemon_raidquaza |   File "/usr/local/lib/python3.9/site-packages/dbl/client.py", line 160, in post_guild_count
pokemon_raidquaza |     await self.http.post_guild_count(guild_count, shard_count, shard_id)
pokemon_raidquaza |   File "/usr/local/lib/python3.9/site-packages/dbl/http.py", line 168, in post_guild_count
pokemon_raidquaza |     await self.request('POST', '/bots/stats', json=payload)
pokemon_raidquaza |   File "/usr/local/lib/python3.9/site-packages/dbl/http.py", line 93, in request
pokemon_raidquaza |     async with rate_limiter:  # this works but doesn't 'save' over restart.
pokemon_raidquaza |   File "<string>", line 6, in __aenter__
pokemon_raidquaza | TypeError: object Lock can't be used in 'await' expression

Code:

from discord.ext import commands

import dbl

class TopGG(commands.Cog):
    """
    This example uses dblpy's autopost feature to post guild count to top.gg every 30 minutes.
    """

    def __init__(self, bot, token):
        self.bot = bot
        self.token = token  # set this to your DBL token
        self.dblpy = dbl.DBLClient(self.bot, self.token, autopost=True)  # Autopost will post your guild count every 30 minutes

    @commands.Cog.listener()
    async def on_guild_post(self):
        print("Server count posted successfully")
... 
from cogs.topggcog import TopGG
...
class Raidquaza(commands.Bot):

    def __init__(self, description):
        super().__init__(command_prefix=[], description=description, pm_help=None,
                         help_attrs=dict(hidden=True))

        self.add_cog(PollCog(self))
        self.add_cog(UtilsCog(self))
        self.add_cog(TopGG(self, config.TOPGG_API_TOKEN))
    ...

full code here:

https://github.com/Breee/raidquaza/blob/master/raidquaza/cogs/topggcog.py https://github.com/Breee/raidquaza/blob/master/raidquaza/bot.py

Esmeray6 commented 3 years ago

This issue occurs on Python 3.9+.

Try to downgrade or send the HTTP requests manually for now. I will close this issue when a fix is implemented.

jgayfer commented 3 years ago

Any update on this guy?

Merry Christmas!

nexy7574 commented 3 years ago

+1

Esmeray6 commented 3 years ago

Fixed in v1.0, the PyPi package will be updated soon.