ChenXu233 / nonebot-plugin-watermarker

一个为nonebot发出的图片添加水印的插件
MIT License
2 stars 0 forks source link

无法正确识别水印文件夹位置 #2

Closed PackageInstaller closed 1 year ago

PackageInstaller commented 1 year ago
05-06 18:56:52 [ERROR] nonebot | Error when running CallingAPI hook. Running cancelled!
Traceback (most recent call last):
  File "/usr/lib/python3.11/urllib/request.py", line 1505, in open_local_file
    stats = os.stat(localfile)
FileNotFoundError: [Errno 2] No such file or directory: '/home/Neko/Bot/zhenxun'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/Neko/Bot/zhenxun_bot/bot.py", line 33, in <module>
    nonebot.run()
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/__init__.py", line 309, in run
    get_driver().run(*args, **kwargs)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/drivers/fastapi.py", line 198, in run
    uvicorn.run(
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/uvicorn/main.py", line 578, in run
    server.run()
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/uvicorn/server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/message.py", line 141, in _check_matcher
    await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/message.py", line 187, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 753, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 728, in simple_run
    await handler(
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/dependencies/__init__.py", line 108, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "/home/Neko/Bot/zhenxun_bot/plugins/ai/__init__.py", line 65, in _
    await ai.finish(hello())
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 481, in finish
    await cls.send(message, **kwargs)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 466, in send
    return await bot.send(event=event, message=_message, **kwargs)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot_plugin_guild_patch/__init__.py", line 30, in patched_send
    return await original_send(self, event, message, **kwargs)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/adapters/onebot/v11/bot.py", line 220, in send
    return await self.__class__.send_handler(self, event, message, **kwargs)
  File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/adapters/onebot/v11/bot.py", line 174, in send
    return await bot.send_msg(**params)
> File "/home/Neko/.cache/pypoetry/virtualenvs/zhenxun-bot-uIXH1-31-py3.11/lib/python3.11/site-packages/nonebot/internal/adapter/bot.py", line 83, in call_api
    await asyncio.gather(*coros)
  File "/home/Neko/Bot/zhenxun_bot/extensive_plugin/nonebot_plugin_watermarker/__init__.py", line 36, in _handle
    if image := str2img(file):
  File "/home/Neko/Bot/zhenxun_bot/extensive_plugin/nonebot_plugin_watermarker/fuctions.py", line 32, in str2img
    bytes = urllib.request.urlopen(string).read()
  File "/usr/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.11/urllib/request.py", line 519, in open
    response = self._open(req, data)
  File "/usr/lib/python3.11/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.11/urllib/request.py", line 1483, in file_open
    return self.open_local_file(req)
  File "/usr/lib/python3.11/urllib/request.py", line 1522, in open_local_file
    raise URLError(exp)
urllib.error.URLError: <urlopen error [Errno 2] No such file or directory: '/home/Neko/Bot/zhenxun'>

用的是真寻bot,正确的文件夹路径应该是/home/Neko/Bot/zhenxun_bot/extensive_plugin/nonebot_plugin_watermarker/watermarker_image,但是运行的时候就出现上面的报错

图片如下 image image

PackageInstaller commented 1 year ago

感觉如

https://github.com/X-Skirt-X/nonebot-plugin-watermarker/issues/1#issuecomment-1532640870

所说,本地的图片都不行,但是生成图片有报错但是有部分可以加上水印 image image image

ChenXu233 commented 1 year ago

本地图片的问题不知道是不是base64解码的问题,之前定位到都是base64出的问题,网络图片的问题的话可能和urllib有关系(((在改了在改了)

ChenXu233 commented 1 year ago

网络图片的水印添加已经解决,但是本地图片还是存在可能贴不上的情况,请等待后续我把问题揪出来(

PackageInstaller commented 1 year ago

git pull了一下,这下连生成的图都打不上水印了 image

Nenot233 commented 1 year ago

05-10 13:42:12 [ERROR] nonebot | Error when running CallingAPI hook. Running cancelled! Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-bot-l9AehN_x-py3.9\lib\site-packages\nonebot\adapters\onebot\v11\bot.py", line 174, in send return await bot.send_msg(*params) File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-bot-l9AehN_x-py3.9\lib\site-packages\nonebot\internal\adapter\bot.py", line 83, in call_api await asyncio.gather(coros) File "D:\BOT\zhenxun_bot\extensive_plugin\nonebot_plugin_watermarker__init__.py", line 37, in _handle image_size = image.size AttributeError: 'coroutine' object has no attribute 'size' C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py:1890: RuntimeWarning: coroutine 'str2img' was never awaited handle = self._ready.popleft() RuntimeWarning: Enable tracemalloc to get the object allocation traceback +1

ChenXu233 commented 1 year ago

05-10 13:42:12 [ERROR] nonebot | Error when running CallingAPI hook. Running cancelled! Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-bot-l9AehN_x-py3.9\lib\site-packages\nonebot\adapters\onebot\v11\bot.py", line 174, in send return await bot.send_msg(*params) File "C:\Users\Administrator\AppData\Local\pypoetry\Cache\virtualenvs\zhenxun-bot-l9AehN_x-py3.9\lib\site-packages\nonebot\internal\adapter\bot.py", line 83, in call_api await asyncio.gather(coros) File "D:\BOT\zhenxun_bot\extensive_plugin\nonebot_plugin_watermarkerinit.py", line 37, in _handle image_size = image.size AttributeError: 'coroutine' object has no attribute 'size' C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py:1890: RuntimeWarning: coroutine 'str2img' was never awaited handle = self._ready.popleft() RuntimeWarning: Enable tracemalloc to get the object allocation traceback +1

忘记加await了( 现在你再试试

PackageInstaller commented 1 year ago

git pull后,只要是涉及图片,终端会卡住,无法做出任何回应(gocq能正常收到信息) 输入exit后才能退出该状态继续回应,但是生成的图没有带上水印,并且再次涉及图片的地方又会卡在这里

image

ChenXu233 commented 1 year ago

草,我忘记删breakpoint了😰

ChenXu233 commented 1 year ago

这回应该没有问题了,我在自己的bot上试了一下

git pull后,只要是涉及图片,终端会卡住,无法做出任何回应(gocq能正常收到信息) 输入exit后才能退出该状态继续回应,但是生成的图没有带上水印,并且再次涉及图片的地方又会卡在这里

image

PackageInstaller commented 1 year ago

好也,应该是没问题了

PackageInstaller commented 1 year ago

那我closed咯