lgc-NB2Dev / nonebot-plugin-picmcstat

A NoneBot2 plugin generates a pic from a Minecraft server's MOTD
MIT License
14 stars 2 forks source link

获取服务器状态/画服务器状态图出错 #9

Closed Mepuru closed 11 months ago

Mepuru commented 11 months ago
08-07 12:01:09 [SUCCESS] nonebot | OneBot V11 1093055754 | [message.private.friend]: Message 30491 from 2066099262 '查服'
08-07 12:01:09 [INFO] nonebot | Event will be handled by Matcher(type='message', module=nonebot_plugin_picmcstat.__main__)
08-07 12:01:09 [ERROR] nonebot_plugin_picmcstat | 获取服务器状态/画服务器状态图出错
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot\__init__.py", line 333, in run
    get_driver().run(*args, **kwargs)
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot\drivers\fastapi.py", line 199, in run
    uvicorn.run(
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\uvicorn\main.py", line 587, in run
    server.run()
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\uvicorn\server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Users\28305\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
  File "C:\Users\28305\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "C:\Users\28305\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "C:\Users\28305\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "C:\Users\28305\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 607, in run_forever
    self._run_once()
  File "C:\Users\28305\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1922, in _run_once
    handle._run()
  File "C:\Users\28305\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot\message.py", line 467, in check_and_run_matcher
    await _run_matcher(
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot\message.py", line 419, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 759, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 734, in simple_run
    await handler(
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot\dependencies\__init__.py", line 108, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot_plugin_picmcstat\__main__.py", line 35, in shortcut_handler
    await matcher.finish(await draw(host, svr_type))
> File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot_plugin_picmcstat\draw.py", line 319, in draw
    draw_java(await (await JavaServer.async_lookup(ip)).async_status(), ip),
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot_plugin_picmcstat\draw.py", line 253, in draw_java
    if mod_list and (li := format_list("§7Mod列表: ", mod_list)):
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot_plugin_picmcstat\draw.py", line 164, in format_list
    text_img = [format_extra(x) for x in sample if x]
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot_plugin_picmcstat\draw.py", line 164, in <listcomp>
    text_img = [format_extra(x) for x in sample if x]
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot_plugin_picmcstat\draw.py", line 153, in format_extra
    format_code_to_bbcode(extra),
  File "D:\Nonebot2\KuriKana-Nonebot2\.venv\Lib\site-packages\nonebot_plugin_picmcstat\util.py", line 56, in format_code_to_bbcode
    parts = text.split("§")
AttributeError: 'dict' object has no attribute 'split'
08-07 12:01:09 [INFO] nonebot | Matcher(type='message', module=nonebot_plugin_picmcstat.__main__) running complete

e6d70be8bb2e2ff4762076b14dc3034d

lgc2333 commented 11 months ago

可以告诉我下面这段代码的输出吗

import asyncio
import json
from mcstatus import JavaServer

IP = 'hypixel.net'  # 换成你的服务器 IP

async def main():
    svr = await JavaServer.async_lookup(IP)
    res = await svr.async_status()
    json_str = json.dumps(res.raw, ensure_ascii=False, indent=2)
    print(json_str)

asyncio.run(main())

Tip: 虚拟环境运行 python,粘贴后回车

qingtian-crazy commented 7 months ago

所以结果是 怎么解决的啊

qingtian-crazy commented 7 months ago

我也有类似的报错

ERROR nonebot_plugin_picmcstat >> 获取服务器状态/画服务器状态图出错 Traceback (most recent call last):

File "/bot/atri/main.py", line 9, in ATRI.run() │ └ <function run at 0x7f9e5a2385e0> └ <module 'ATRI' from '/bot/atri/ATRI/init.py'>

File "/bot/atri/ATRI/init.py", line 36, in run nonebot.run(log_level=log_level) │ │ └ 'warning' │ └ <function run at 0x7f9e5af8f760> └ <module 'nonebot' from '/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot/init....

File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot/init.py", line 331, in run get_driver().run(*args, **kwargs) │ │ └ {'log_level': 'warning'} │ └ () └ <function get_driver at 0x7f9e5af8f5b0> File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot/drivers/fastapi.py", line 201, in run uvicorn.run( │ └ <function run at 0x7f9e5a184670> └ <module 'uvicorn' from '/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/uvicorn/init.... File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/uvicorn/main.py", line 578, in run server.run() │ └ <function Server.run at 0x7f9e5a184820> └ <uvicorn.server.Server object at 0x7f9e35181ff0> File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/uvicorn/server.py", line 61, in run return asyncio.run(self.serve(sockets=sockets)) │ │ │ │ └ None │ │ │ └ <function Server.serve at 0x7f9e5a1848b0> │ │ └ <uvicorn.server.Server object at 0x7f9e35181ff0> │ └ <function run at 0x7f9e5c118550> └ <module 'asyncio' from '/usr/lib/python3.10/asyncio/init.py'> File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) │ │ └ <coroutine object Server.serve at 0x7f9e382e9ee0> │ └ <method 'run_until_complete' of 'uvloop.loop.Loop' objects> └ File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot/message.py", line 476, in check_and_run_matcher await _run_matcher( └ <function _run_matcher at 0x7f9e5aeaf010> File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot/message.py", line 428, in _run_matcher await matcher.run(bot, event, state, stack, dependency_cache) │ │ │ │ │ │ └ {<function _command at 0x7f9e5adb7d00>: <Task finished name='Task-1743' coro=<_command() done, defined at /root/.cache/pypoet... │ │ │ │ │ └ <contextlib.AsyncExitStack object at 0x7f9dea3ecc40> │ │ │ │ └ {'_prefix': {'command': None, 'raw_command': None, 'command_arg': None, 'command_start': None, 'command_whitespace': None}, '... │ │ │ └ GroupMessageEvent(time=1701623220, self_id=3218305779, post_type='message', sub_type='normal', user_id=1445352985, message_ty... │ │ └ Bot(type='OneBot V11', self_id='3218305779') │ └ <function Matcher.run at 0x7f9e5adb7a30> └ Matcher(type='message', module=nonebot_plugin_picmcstat.main, lineno=59) File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 846, in run await self.simple_run(bot, event, state, stack, dependency_cache) │ │ │ │ │ │ └ {<function _command at 0x7f9e5adb7d00>: <Task finished name='Task-1743' coro=<_command() done, defined at /root/.cache/pypoet... │ │ │ │ │ └ <contextlib.AsyncExitStack object at 0x7f9dea3ecc40> │ │ │ │ └ {'_prefix': {'command': None, 'raw_command': None, 'command_arg': None, 'command_start': None, 'command_whitespace': None}, '... │ │ │ └ GroupMessageEvent(time=1701623220, self_id=3218305779, post_type='message', sub_type='normal', user_id=1445352985, message_ty... │ │ └ Bot(type='OneBot V11', self_id='3218305779') │ └ <function simple_run at 0x7f9e4af3b130> └ Matcher(type='message', module=nonebot_plugin_picmcstat.main, lineno=59)

File "/bot/atri/ATRI/patch.py", line 41, in simple_run await handler( └ Dependent(call=shortcut_handler)

File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot/dependencies/init.py", line 113, in call return await cast(Callable[..., Awaitable[R]], self.call)(**values) │ │ │ │ │ │ └ {'matcher': Matcher(type='message', module=nonebot_plugin_picmcstat.main, lineno=59)} │ │ │ │ │ └ <function get_shortcut_handler..shortcut_handler at 0x7f9e143cd1b0> │ │ │ │ └ Dependent(call=shortcut_handler) │ │ │ └ ~R │ │ └ typing.Awaitable │ └ typing.Callable └ <function cast at 0x7f9e5c1a0280> File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot_plugin_picmcstat/main.py", line 48, in shortcut_handler img = await draw(host, svr_type) │ │ │ │ └ {'_prefix': {'command': None, 'raw_command': None, 'command_arg': None, 'command_start': None, 'command_whitespace': None}, '... │ │ │ └ GroupMessageEvent(time=1701623220, self_id=3218305779, post_type='message', sub_type='normal', user_id=1445352985, message_ty... │ │ └ Bot(type='OneBot V11', self_id='3218305779') │ └ <function simple_run at 0x7f9e4af3b130> └ Matcher(type='message', module=nonebot_plugin_picmcstat.main, lineno=59)

File "/bot/atri/ATRI/patch.py", line 41, in simple_run await handler( └ Dependent(call=shortcut_handler)

File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot/dependencies/init.py", line 113, in call return await cast(Callable[..., Awaitable[R]], self.call)(**values) │ │ │ │ │ │ └ {'matcher': Matcher(type='message', module=nonebot_plugin_picmcstat.main, lineno=59)} │ │ │ │ │ └ <function get_shortcut_handler..shortcut_handler at 0x7f9e143cd1b0> │ │ │ │ └ Dependent(call=shortcut_handler) │ │ │ └ ~R │ │ └ typing.Awaitable │ └ typing.Callable <function cast at 0x7f9e5c1a0280> File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot_plugin_picmcstat/main.py", line 48, in shortcut_handler img = await draw(host, svr_type) │ │ └ 'be' │ └ 'qymc.sytes.net:19132' └ <function draw at 0x7f9e14337d00>

File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot_plugin_picmcstat/draw.py", line 329, in draw return draw_bedrock(status, original_ip) │ │ └ 'qymc.sytes.net:19132' │ └ BedrockStatusResponse(players=BedrockStatusPlayers(online=0, max=202312), version=BedrockStatusVersion(name='1.20.41', protoc... └ <function draw_bedrock at 0x7f9e14337be0> File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot_plugin_picmcstat/draw.py", line 276, in draw_bedrock motd = strip_lines(res.motd) │ │ └ Motd(parsed=['齐悦幻想'], raw='齐悦幻想', bedrock=True) │ └ BedrockStatusResponse(players=BedrockStatusPlayers(online=0, max=202312), version=BedrockStatusVersion(name='1.20.41', protoc... └ <function strip_lines at 0x7f9e14337400> File "/root/.cache/pypoetry/virtualenvs/atri-TKW06R_y-py3.10/lib/python3.10/site-packages/nonebot_plugin_picmcstat/util.py", line 44, in strip_lines txt = "\n".join([x.strip() for x in txt.splitlines()]) └ Motd(parsed=['齐悦幻想'], raw='齐悦幻想', bedrock=True)

AttributeError: 'Motd' object has no attribute 'splitlines'