从osu!api获取请求时的元组和列表问题(Python)

时间:2017-10-25 09:53:31

标签: python list

我有一个错误,我试图修复大约6个小时。 谁能帮我?是的,它是Python 3.6,使用osuapi库和discord.py

async def stats(self, ctx):
    stat = _osu.get_user(username=ctx.args[0])
    stats = list(stat)
    embed = discord.Embed(title="osu!stats", description="Using Official osu!api", color=0xfc89ac)
    embed.add_field(name="Уровень", value=stats[0].level)
    embed.add_field(name="Глобальный ранг", value=stats[0].username)
    embed.add_field(name="PP-очки", value=stats[0].username)
    embed.add_field(name="Страна", value=pycountry.countries.get(alpha_2=stats[0].country).name)
    embed.add_field(name="Число игр", value=stats[0].playcount)
    embed.set_author(name=stats[0].username, url="https://osu.ppy.sh/u/"+stats[0].user_id)
    await self.bot.say(Mention.mention(ctx.message.author)+", вот статы игрока "+stats[0].username, embed=embed)

这是追溯:

    Ignoring exception in command osu stats
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\osuapi\connectors.py", line 46, in process_request
    resp = yield from self.sess.get(endpoint, params=data)
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\client.py", line 555, in __iter__
    resp = yield from self._coro
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\client.py", line 198, in _request
    conn = yield from self._connector.connect(req)
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\connector.py", line 304, in connect
    yield from self._create_connection(req)
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\connector.py", line 578, in _create_connection
    transport, proto = yield from self._create_direct_connection(req)
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\connector.py", line 589, in _create_direct_connection
    hosts = yield from self._resolve_host(req.host, req.port)
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\connector.py", line 561, in _resolve_host
    self._resolver.resolve(host, port, family=self._family)
  File "C:\Program Files\Python36\lib\site-packages\aiohttp\resolver.py", line 29, in resolve
    host, port, type=socket.SOCK_STREAM, family=family)
AssertionError: yield from wasn't used with future

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\discord\ext\commands\core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "C:\Users\NukDo\PycharmProjects\nukdotcom\cogs\osu_cog.py", line 21, in stats
    stats = list(stat)
  File "C:\Program Files\Python36\lib\site-packages\osuapi\connectors.py", line 57, in process_request
    resp.close()
UnboundLocalError: local variable 'resp' referenced before assignment

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "C:\Program Files\Python36\lib\site-packages\discord\ext\commands\core.py", line 634, in invoke
    yield from ctx.invoked_subcommand.invoke(ctx)
  File "C:\Program Files\Python36\lib\site-packages\discord\ext\commands\core.py", line 374, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "C:\Program Files\Python36\lib\site-packages\discord\ext\commands\core.py", line 54, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnboundLocalError: local variable 'resp' referenced before assignment

1 个答案:

答案 0 :(得分:0)

好的,我有一个答案!使用ReqConnector代替AHConnector。这就是全部!