Closed KomoriDev closed 1 year ago
没有返回可能是网络超时?有试过在本地网络环境下测试API是否能正常工作嘛?
另外,尝试把下面的except部分解除注释查看一下日志呢
@real_esrgan.got("img", prompt="请上传需要超分辨率重建的图片", parameterless=[HandleCancellation("已取消")])
async def real_esrgan_handle_img(event: MessageEvent | GuildMessageEvent , state: T_State):
# 先拿到需要转换的图
for seg in state["img"]:
if seg.type == "image":
img = await get_img(seg.data["url"])
break
else:
await real_esrgan.finish(Message(f"[CQ:at,qq={state['id']}]不是图捏"))
# 下面来处理图片
try:
json_data = img_encode_to_json(img, state['mode']) # 先获取图片并进行编码
if json_data is None:
await real_esrgan.finish(Message(f"[CQ:at,qq={state['id']}]服务器无法接收到这张图捏,要不重试试试?"))
result = await get_result(json_data, api=api) # 然后进行超分辨率重建
if result is None:
await real_esrgan.finish(Message(f"[CQ:at,qq={state['id']}]这张图没能被正确解析,可能网络连接失败或者是由于远程服务器免费额度耗尽,如果是后者建议联系管理员使用自建仓库(免费)"))
img = img_decode_from_json(result) # 获取重建后图片并进行解码发送
await real_esrgan.finish(MessageSegment.image(img))
except Exception as e:
...
# 把下面这里解除注释
print('错误类型是', e.__class__.__name__)
print('错误明细是', e)
删掉 try... except
后报错
01-26 20:37:41 [ERROR] nonebot | Running Matcher(type='message', module=plugins.pixiv.Resolution_Ratio) failed.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 129, in _main
return self._bootstrap(parent_sentinel)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 315, in _bootstrap
self.run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\linxi-doM17b9W-py3.10\lib\site-packages\nonebot_plugin_reboot\reloader.py", line 27, in _run
_nb_run(*args, **kwargs)
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\linxi-doM17b9W-py3.10\lib\site-packages\nonebot\__init__.py", line 273, in run
get_driver().run(*args, **kwargs)
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\linxi-doM17b9W-py3.10\lib\site-packages\nonebot\drivers\fastapi.py", line 172, in run
uvicorn.run(
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\linxi-doM17b9W-py3.10\lib\site-packages\uvicorn\main.py", line 569, in run
server.run()
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\linxi-doM17b9W-py3.10\lib\site-packages\uvicorn\server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 633, in run_until_complete
self.run_forever()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 321, in run_forever
super().run_forever()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 600, in run_forever
self._run_once()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1896, in _run_once
handle._run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\linxi-doM17b9W-py3.10\lib\site-packages\nonebot\message.py", line 142, in _check_matcher
await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
> File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\linxi-doM17b9W-py3.10\lib\site-packages\nonebot\message.py", line 188, in _run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\linxi-doM17b9W-py3.10\lib\site-packages\nonebot\internal\matcher\matcher.py", line 727, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\linxi-doM17b9W-py3.10\lib\site-packages\nonebot\internal\matcher\matcher.py", line 702, in simple_run
await handler(
File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\linxi-doM17b9W-py3.10\lib\site-packages\nonebot\dependencies\__init__.py", line 108, in __call__
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
File "C:\linxi_bot\plugins\pixiv\Resolution_Ratio\__init__.py", line 57, in real_esrgan_handle_img
result = await get_result(json_data, api=api) # 然后进行超分辨率重建
TypeError: get_result() got an unexpected keyword argument 'api'
找到问题了,是我的utils.py出现了问题 我写的是:
async def get_result(json_data: dict) -> str:
按照源码改成
async def get_result(json_data: dict, *, api) -> str:
成功,已经有返回了,谢谢指点
没有返回图片或报错![image](https://user-images.githubusercontent.com/110453675/214495933-ce653a62-67ba-4f67-8452-51756c00ed7a.png)
init.py
utils.py
自建的api,可以在仓库中运行,但是在QQ中却没有返回。日志也只显示了接受消息