Yuri-YuzuChaN / maimaiDX

基于HoshinoBot V2的舞萌DX查询插件,移植自mai-bot开源项目
MIT License
198 stars 32 forks source link

【报错】只要关于关于歌曲的指令会报错 #95

Closed Moxiner closed 1 year ago

Moxiner commented 1 year ago

环境

Yuri-YuzuChaN commented 1 year ago

启动bot时数据还没初始化就使用指令就会出现这个情况,控制台会有输出 正在获取maimai曲目数据 等这种消息,只有显示 maimai数据获取完成 后才能使用指令,不然就会出现这种情况

Moxiner commented 1 year ago

重启了一下控制台,确实没有获取成功,它有这样的报错


[2023-07-12 17:22:18,643 maimaiDX] ERROR: maimaiDX曲目数据获取失败,请检查网络环境。已切换至本地暂存文件
Task exception was never retrieved
future: <Task finished name='Task-14' coro=<CQHttp._handle_event_with_response() done, defined at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py:604> exception=FileNotFoundError(2, 'No such file or directory')>
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py", line 606, in _handle_event_with_response
    response = await self._handle_event(payload)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py", line 599, in _handle_event
    filter(lambda r: r is not None, await
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\bus.py", line 60, in emit
    results += await run_async_funcs(self._subscribers[event], *args,
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\utils.py", line 40, in run_async_funcs
    results += await asyncio.gather(*coros)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\maimai.py", line 88, in get_music
    await mai.get_music()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 332, in get_music
    self.total_list = await get_music_list()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 233, in get_music_list
    async with aiofiles.open(os.path.join(static, 'music_data.json'), 'r', encoding='utf-8') as f:
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiofiles\base.py", line 98, in __aenter__
    self._obj = await self._coro
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiofiles\threadpool\__init__.py", line 97, in _open
    f = yield from loop.run_in_executor(executor, cb)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\thread.py", line 57, in run    result = self.fn(*self.args, **self.kwargs)
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Administrator\\Desktop\\Maibot\\HoshinoBot\\HoshinoBot\\hoshino\\modules\\maimaiDX\\static\\music_data.json'
Moxiner commented 1 year ago

我是用的是轻量云服务器,网络访问没有问题,是需要去云操作台中关闭特定端口的防火墙嘛?

Yuri-YuzuChaN commented 1 year ago

哪个服务商的轻量机,什么地区的,如果是国内机一般不会有问题。不需要改端口

Moxiner commented 1 year ago

阿里云,华北,轻量云服务器,Win Server 2019

Yuri-YuzuChaN commented 1 year ago

这不应该会超时吧,获取数据的时候等了很久吗,重启几次都是这样吗?

Moxiner commented 1 year ago

确实是超时 完整报错如下

[2023-07-12 17:35:10,935 maimaiDX] INFO: 正在获取maimai所有曲目信息
[2023-07-12 17:35:41,546 maimaiDX] ERROR: Error: Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 227, in get_music_list
    data = await obj_data.json()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\client_reqrep.py", line 1099, in json
    await self.read()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\client_reqrep.py", line 1037, in read
    self._body = await self.content.read()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\streams.py", line 375, in read
    block = await self.readany()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\streams.py", line 397, in readany
    await self._wait("readany")
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\streams.py", line 304, in _wait
    await waiter
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\helpers.py", line 721, in __exit__
    raise asyncio.TimeoutError from None
asyncio.exceptions.TimeoutError

[2023-07-12 17:35:41,547 maimaiDX] ERROR: maimaiDX曲目数据获取失败,请检查网络环境。已切换至本地暂存文件
Task exception was never retrieved
future: <Task finished name='Task-14' coro=<CQHttp._handle_event_with_response() done, defined at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py:604> exception=FileNotFoundError(2, 'No such file or directory')>
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py", line 606, in _handle_event_with_response
    response = await self._handle_event(payload)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py", line 599, in _handle_event
    filter(lambda r: r is not None, await
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\bus.py", line 60, in emit
    results += await run_async_funcs(self._subscribers[event], *args,
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\utils.py", line 40, in run_async_funcs
    results += await asyncio.gather(*coros)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\maimai.py", line 88, in get_music
    await mai.get_music()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 332, in get_music
    self.total_list = await get_music_list()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 233, in get_music_list
    async with aiofiles.open(os.path.join(static, 'music_data.json'), 'r', encoding='utf-8') as f:
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiofiles\base.py", line 98, in __aenter__
    self._obj = await self._coro
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiofiles\threadpool\__init__.py", line 97, in _open
    f = yield from loop.run_in_executor(executor, cb)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Administrator\\Desktop\\Maibot\\HoshinoBot\\HoshinoBot\\hoshino\\modules\\maimaiDX\\static\\music_data.json'
Moxiner commented 1 year ago

等待30秒左右,重启多次都是这样的

Yuri-YuzuChaN commented 1 year ago

那就只能先临时手动获取数据保存到本地了

Moxiner commented 1 year ago

啊这.....那我该如何获取数据并保存到本地呢?

Yuri-YuzuChaN commented 1 year ago

浏览器访问

然后把这两个文件放在 static 文件夹

Moxiner commented 1 year ago

我按照您说的已经将music_data.json ,all_alias.json添加进static文件夹中了,但是它还会报错,并且貌似还缺少一个名为 chart_stats.json 的文件


[2023-07-12 18:03:04,171 maimaiDX] ERROR: maimaiDX数据获取错误,请检查网络环境。已切换至本地暂存文件
Task exception was never retrieved
future: <Task finished name='Task-14' coro=<CQHttp._handle_event_with_response() done, defined at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py:604> exception=FileNotFoundError(2, 'No such file or directory')>
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py", line 606, in _handle_event_with_response
    response = await self._handle_event(payload)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py", line 599, in _handle_event
    filter(lambda r: r is not None, await
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\bus.py", line 60, in emit
    results += await run_async_funcs(self._subscribers[event], *args,
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\utils.py", line 40, in run_async_funcs
    results += await asyncio.gather(*coros)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\maimai.py", line 88, in get_music
    await mai.get_music()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 332, in get_music
    self.total_list = await get_music_list()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 248, in get_music_list
    async with aiofiles.open(os.path.join(static, 'chart_stats.json'), 'r', encoding='utf-8') as f:
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiofiles\base.py", line 98, in __aenter__
    self._obj = await self._coro
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiofiles\threadpool\__init__.py", line 97, in _open
    f = yield from loop.run_in_executor(executor, cb)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\thread.py", line 57, in run    result = self.fn(*self.args, **self.kwargs)
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Administrator\\Desktop\\Maibot\\HoshinoBot\\HoshinoBot\\hoshino\\modules\\maimaiDX\\static\\chart_stats.json'
[2023-07-12 18:03:15,027 bangumi] INFO: Scheduled job mikan_poller start.
[2023-07-12 18:03:25,143 bangumi] ERROR: [get_rss] Error: HTTPSConnectionPool(host='mikanani.me', port=443): Max retries exceeded with url: /RSS/MyBangumi?token= (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000002DC0FB78280>, 'Connection to mikanani.me timed out. (connect timeout=10)'))
[2023-07-12 18:03:25,157 bangumi] INFO: 订阅缓存为空,已加载至最新
[2023-07-12 18:03:25,165 bangumi] INFO: Scheduled job mikan_poller completed.
[2023-07-12 18:05:08,756 nonebot] INFO: Self: 379389560, Message -1080717014 from -----------@[群:-----------]: 'b50'
[2023-07-12 18:05:08,787 maimaiDX] INFO: Message -1080717014 triggered best_50.
[2023-07-12 18:05:20,485 nonebot] INFO: Self: 379389560, Message ------------ from -----------@[群:-----------]: '草'
[2023-07-12 18:05:30,172 maimaiDX] ERROR: <class 'AttributeError'> occured when best_50 handling message -1080717014.
[2023-07-12 18:05:30,173 maimaiDX] ERROR: 'MaiMusic' object has no attribute 'total_list'
Traceback (most recent call last):
 File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\msghandler.py", line 23, in handle_message
    await service_func.func(bot, event)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\maimai.py", line 559, in best_50
    await bot.send(ev, await generate(payload), at_sender=True)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimai_best_50.py", line 385, in generate
    pic = await draw_best.draw()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimai_best_50.py", line 285, in draw
    await self.whiledraw(self.sdBest, True)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimai_best_50.py", line 208, in whiledraw
    dxscore = sum(mai.total_list.by_id(str(info.song_id)).charts[info.level_index].notes) * 3
AttributeError: 'MaiMusic' object has no attribute 'total_list'
Yuri-YuzuChaN commented 1 year ago

还有一个 https://www.diving-fish.com/api/maimaiprober/chart_stats 保存 chart_stats.json 后续我找找解决办法

Yuri-YuzuChaN commented 1 year ago

问一下你用服务器的浏览器访问这些网站是不是秒开

Moxiner commented 1 year ago

草,结案了,水鱼大佬的服务器炸了,https://www.diving-fish.com/api/maimaiprober/chart_stats 500 了 pCf7TC8.png

Yuri-YuzuChaN commented 1 year ago

草,结案了,水鱼大佬的服务器炸了,https://www.diving-fish.com/api/maimaiprober/chart_stats 500 了 pCf7TC8.png

噢我打错了,是 https://www.diving-fish.com/api/maimaidxprober/chart_stats

Moxiner commented 1 year ago

啊这

Moxiner commented 1 year ago

文件补齐后还是有上述报错,网页说不上秒开,但都是5秒内开(应该是单纯的性能卡,并非网络卡)

Moxiner commented 1 year ago

但是加载本地数据不报错了

Yuri-YuzuChaN commented 1 year ago

先用着本地的吧,五秒内的话其实都能接受,有些机器的网络环境不太行,我后面想想解决办法

Moxiner commented 1 year ago

虽然但是,用本地输入指令也会报错

Moxiner commented 1 year ago

只是在启动时加载本地数据的栈不会报错了

Moxiner commented 1 year ago

我写一下关于获取网络数据的测试代码

Yuri-YuzuChaN commented 1 year ago

什么报错

Moxiner commented 1 year ago
[2023-07-12 18:22:43,611 nonebot] INFO: Self: 379389560, Message 1872052308 from 2665348076@[群:1059865060]: 'b50'
[2023-07-12 18:22:43,612 maimaiDX] INFO: Message 1872052308 triggered best_50.
[2023-07-12 18:22:44,912 maimaiDX] ERROR: <class 'AttributeError'> occured when best_50 handling message 1872052308.
[2023-07-12 18:22:44,914 maimaiDX] ERROR: 'MaiMusic' object has no attribute 'total_list'
Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\msghandler.py", line 23, in handle_message
    await service_func.func(bot, event)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\maimai.py", line 559, in best_50
    await bot.send(ev, await generate(payload), at_sender=True)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimai_best_50.py", line 385, in generate
    pic = await draw_best.draw()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimai_best_50.py", line 285, in draw
    await self.whiledraw(self.sdBest, True)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimai_best_50.py", line 208, in whiledraw
    dxscore = sum(mai.total_list.by_id(str(info.song_id)).charts[info.level_index].notes) * 3
AttributeError: 'MaiMusic' object has no attribute 'total_list'
Yuri-YuzuChaN commented 1 year ago

这是没获取成功

Moxiner commented 1 year ago

这是啥原因啊!!🤔🤔🤔 我文件都加进去了,JSON格式也没错,编码 utf8 pCfqpX4.png

Moxiner commented 1 year ago

我写了一段测试代码证明我可以访问这些网站,但可能我处理有些问题,还是报错了(不知道对整体代码有没有影响) 代码

import aiohttp
import asyncio

async def main():
    async with aiohttp.request('GET', 'https://www.diving-fish.com/api/maimaidxprober/music_data', timeout=aiohttp.ClientTimeout(total=30)) as music_data:
        print(f"obj_stats.status = {music_data.status}")
        if music_data.status != 200:
            print("music data not connect")

    async with aiohttp.request('GET', 'https://www.diving-fish.com/api/maimaidxprober/chart_stats', timeout=aiohttp.ClientTimeout(total=30)) as chart_stats:
        print(f"obj_stats.status = {chart_stats.status}")
        if chart_stats.status != 200:
            print("chart stats not connect")

    async with aiohttp.request('GET', 'https://api.yuzuai.xyz/maimaidx/maimaidxalias', timeout=aiohttp.ClientTimeout(total=30)) as alias_data:
        print(f"alias_data.status.status = {alias_data.status}")
        if alias_data.status != 200:
            print("alias data not connect")

asyncio.run(main())

控制台输出

obj_stats.status = 200
obj_stats.status = 200
alias_data.status.status = 200
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000020213F191F0>
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line
719, in call_soon
    self._check_closed()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line
508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000020213F191F0>
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line
719, in call_soon
    self._check_closed()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line
508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Yuri-YuzuChaN commented 1 year ago

访问是肯定能访问的,响应慢罢了,之前有人用了三分钟才获取到数据

Moxiner commented 1 year ago

单独写代码片段是能访问的,整体代码就炸了 :( 而且,现在就算补全文件也不能使用有关歌曲的指令

Yuri-YuzuChaN commented 1 year ago

尝试修了,我中转了一下查分器所有曲目数据,如果获取水鱼的超时就从我的服务器获取 https://github.com/Yuri-YuzuChaN/maimaiDX/commit/2223a5b4b75e00a8b30fd47485e9dbd0c5c35ea1 ,还有就是一定一定要获取完数据再使用指令,注意看完log信息,不知道你服务器获取别名的时候有没有超时

Moxiner commented 1 year ago

辛苦大佬了,我去试试

Moxiner commented 1 year ago

好消息:能获取到了 (但好像也超时了,我不理解 坏消息:还是报错了 报错代码

[2023-07-13 15:42:50,103 maimaiDX] ERROR: 从diving-fish获取maimaiDX数据获取超时,正在使用yuzuapi中转获取单曲数据
Task exception was never retrieved
future: <Task finished name='Task-14' coro=<CQHttp._handle_event_with_response() done, defined at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py:604> exception=TypeError('Object of type coroutine is not JSON serializable')>
Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 268, in get_music_list
    chart_stats = await obj_stats.json()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\client_reqrep.py", line 1099, in json
    await self.read()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\client_reqrep.py", line 1037, in read
    self._body = await self.content.read()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\streams.py", line 375, in read
    block = await self.readany()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\streams.py", line 397, in readany
    await self._wait("readany")
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\streams.py", line 304, in _wait
    await waiter
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\helpers.py", line 721, in __exit__
    raise asyncio.TimeoutError from None
asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py", line 606, in _handle_event_with_response
    response = await self._handle_event(payload)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py", line 599, in _handle_event
    filter(lambda r: r is not None, await
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\bus.py", line 60, in emit
    results += await run_async_funcs(self._subscribers[event], *args,
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\utils.py", line 40, in run_async_funcs
    results += await asyncio.gather(*coros)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\maimai.py", line 88, in get_music
    await mai.get_music()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 362, in get_music
    self.total_list = await get_music_list()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 277, in get_music_list
    await writefile(chart_file, chart_stats)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 227, in writefile
    await f.write(json.dumps(data, ensure_ascii=False, indent=4))
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 234, in dumps
    return cls(
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\encoder.py", line 201, in encode
    chunks = list(chunks)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\encoder.py", line 438, in _iterencode
    o = _default(o)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type coroutine is not JSON serializable
Moxiner commented 1 year ago

两个服务器都超时时会自动清空 chart_stats.json

Moxiner commented 1 year ago

问题在于三个文件我都手动添加过了,使用查歌指令还是会报错 pChRxFe.png 错误代码和之前一样

Yuri-YuzuChaN commented 1 year ago

chart_stats.json 不会被清空的吧,只有在获取成功的时候才会写文件

Yuri-YuzuChaN commented 1 year ago

噢知道了,协程忘记 await 了,重新clone下,我把await补上去了

Moxiner commented 1 year ago

Moxiner commented 1 year ago

确实不自动清除chart_stats.json ,但是有新的报错(不知道是不是超时的原因

Task exception was never retrieved
future: <Task finished name='Task-14' coro=<CQHttp._handle_event_with_response() done, defined at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py:604> exception=1 validation error for Music
basic_info.is_new
  Input should be a valid string [type=string_type, input_value=False, input_type=bool]
    For further information visit https://errors.pydantic.dev/2.1.2/v/string_type>
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py", line 606, in _handle_event_with_response
    response = await self._handle_event(payload)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\__init__.py", line 599, in _handle_event
    filter(lambda r: r is not None, await
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\bus.py", line 60, in emit
    results += await run_async_funcs(self._subscribers[event], *args,
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiocqhttp\utils.py", line 40, in run_async_funcs
    results += await asyncio.gather(*coros)
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\maimai.py", line 88, in get_music
    await mai.get_music()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 362, in get_music
    self.total_list = await get_music_list()
  File "C:\Users\Administrator\Desktop\Maibot\HoshinoBot\HoshinoBot\hoshino\modules\maimaiDX\libraries\maimaidx_music.py", line 291, in get_music_list
    total_list[num] = Music(stats=_stats, **total_list[num])
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\pydantic\main.py", line 150, in __init__
    __pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Music
basic_info.is_new
  Input should be a valid string [type=string_type, input_value=False, input_type=bool]
    For further information visit https://errors.pydantic.dev/2.1.2/v/string_type
TTsdzb commented 1 year ago

最后一次报错是因为 is_new 属性声明是个字符串,但是实际上 JSON 里是个布尔值

image

image

不太清楚为什么但是我这里能跑

Moxiner commented 1 year ago

嘶……我改一下跑试试

Moxiner commented 1 year ago

最后一次报错是因为 is_new 属性声明是个字符串,但是实际上 JSON 里是个布尔值

image

image

不太清楚为什么但是我这里能跑

我按照你的方法试了,已经可以了,而且响应很快,我在想要不要PR (

Moxiner commented 1 year ago

响应很快是作者大佬搭了一个中转站(或许

Yuri-YuzuChaN commented 1 year ago

?我写的str吗?

TTsdzb commented 1 year ago

?我写的str吗?

PR 吧(

Yuri-YuzuChaN commented 1 year ago

这么神奇?如果是BaseModel的话直接报错才对,我怎么用到现在的

TTsdzb commented 1 year ago

这么神奇?如果是BaseModel的话直接报错才对,我怎么用到现在的

我也想问,刚刚还在好奇为什么我能跑

Moxiner commented 1 year ago

已提交修复此错误的PR #97

Moxiner commented 1 year ago

我也不是很清楚,或许是pydantic版本不一致?(等明天看一下……

TTsdzb commented 1 year ago

我的 pydantic1.10.7