lgc-NB2Dev / YetAnotherPicSearch

Yet another picture search plugin for nonebot2
GNU General Public License v3.0
107 stars 10 forks source link

搜索图片时程序出错 #62

Closed Yangleis closed 1 year ago

Yangleis commented 1 year ago

YetAnotherPicSearch 、 go-cqhttp 、 nonebot 、 Python 版本及操作系统

YetAnotherPicSearch 1.7.8 go-cqhttp v1.0.0-rc3 nonebot v2.0.0rc2 Python 3.10 Ubuntu 22.04.1 LTS x86_64

列出安装的 Python 包

相关依赖已经检查过,和pyproject.toml文件内版本一致。

(nonebot-py3.10) ➜  nonebot pip freeze -l
aiodns==3.0.0
aiofiles==22.1.0
aiohttp==3.8.3
aiosignal==1.3.1
aiosqlite==0.17.0
anyio==3.6.2
APScheduler==3.9.1.post1
arrow==1.2.3
async-timeout==4.0.2
attrs==22.1.0
bbcode==1.1.0
bcrypt==4.0.1
beautifulsoup4==4.11.1
binaryornot==0.4.4
Brotli==1.0.9
cachetools==5.2.0
certifi==2022.9.24
cffi==1.15.1
chardet==5.0.0
charset-normalizer==2.1.1
click==8.1.3
colorama==0.4.6
contourpy==1.0.6
cookiecutter==1.7.3
cssselect==1.2.0
cycler==0.11.0
diskcache==5.4.0
dnspython==2.2.1
email-validator==1.3.0
et-xmlfile==1.1.0
fastapi==0.88.0
fastapi_amis_admin==0.4.2
fastapi_user_auth==0.4.2
fonttools==4.38.0
frozenlist==1.3.3
fuzzywuzzy==0.18.0
-e git+https://ghproxy.com/https://github.com/KimigaiiWuyi/GenshinUID.git@261437f4662b638d7383852cef9e06dfded9cbba#egg=GenshinUID
gitdb==4.0.10
GitPython==3.1.29
greenlet==2.0.1
h11==0.14.0
h2==4.1.0
hpack==4.0.0
httpcore==0.16.2
httptools==0.5.0
httpx==0.23.1
hyperframe==6.0.1
idna==3.4
imageio==2.22.4
Jinja2==3.1.2
jinja2-time==0.2.0
joblib==1.2.0
kiwisolver==1.4.4
Levenshtein==0.20.8
loguru==0.6.0
lxml==4.9.2
Markdown==3.4.1
MarkupSafe==2.1.1
matplotlib==3.6.2
msgpack==1.0.4
multidict==6.0.4
nb-cli==0.6.8
nonebot-adapter-cqhttp==2.0.0b1
nonebot-adapter-onebot==2.2.0
nonebot-plugin-analysis-bilibili==2.4.7
nonebot-plugin-animeres==0.1.5
nonebot-plugin-apscheduler==0.2.0
nonebot-plugin-arktools==0.5.8
nonebot-plugin-chatgpt==0.7.3
nonebot-plugin-covid19-news==0.7
nonebot-plugin-crazy-thursday==0.2.6
nonebot-plugin-ddcheck==0.1.15
nonebot-plugin-epicfree==0.2.5
nonebot-plugin-fortune==0.4.9
nonebot-plugin-help==0.3.1
nonebot-plugin-heweather==0.6.0
nonebot-plugin-htmlrender==0.2.0.1
nonebot-plugin-imageutils==0.1.13.4
nonebot-plugin-logo==0.2.2
nonebot-plugin-memes==0.3.9
nonebot-plugin-moegoe==0.7.4
nonebot-plugin-moyu==0.3.0
nonebot-plugin-petpet==0.3.18
nonebot-plugin-PicMenu==0.2
nonebot-plugin-picstatus==0.3.1
nonebot-plugin-read-60s==0.2.4
nonebot-plugin-repeater==3.1.4
nonebot-plugin-simplemusic==0.1.5
nonebot-plugin-smart-reply==0.0.16
nonebot-plugin-what2eat==0.3.5
nonebot-plugin-withdraw==0.2.3
nonebot-plugin-word-bank2==0.1.6
nonebot2==2.0.0rc2
numpy==1.23.5
openai==0.25.0
OpenAIAuth==0.0.6
opencv-python-headless==4.6.0.66
openpyxl==3.0.10
packaging==21.3
pandas==1.5.2
pandas-stubs==1.5.2.221124
passlib==1.7.4
picimagesearch==3.7.5
Pillow==9.3.0
playwright==1.28.0
poyo==0.5.0
prompt-toolkit==3.0.33
psutil==5.9.4
pycares==4.2.2
pycparser==2.21
pydantic==1.10.2
pyee==9.0.4
pyfiglet==0.8.post1
Pygments==2.13.0
pygtrie==2.5.0
pymdown-extensions==9.9
pyparsing==3.0.9
pyquery==2.0.0
python-dateutil==2.8.2
python-dotenv==0.21.0
python-Levenshtein==0.20.8
python-markdown-math==0.8
python-multipart==0.0.5
python-slugify==7.0.0
pytz==2022.6
pytz-deprecation-shim==0.1.0.post0
PyYAML==6.0
qrcode==7.3.1
rapidfuzz==2.13.2
requests==2.28.1
rfc3986==1.5.0
rtoml==0.9.0
scikit-learn==1.1.3
scipy==1.9.3
Shapely==1.8.5.post1
six==1.16.0
smmap==5.0.0
sniffio==1.3.0
soupsieve==2.3.2.post1
SQLAlchemy==1.4.41
sqlalchemy2-stubs==0.0.2a29
sqlalchemy_database==0.1.0
sqlmodel==0.0.8
sqlmodelx==0.0.4
starlette==0.22.0
tenacity==8.1.0
tencentcloud-sdk-python==3.0.783
text-unidecode==1.3
threadpoolctl==3.1.0
tls-client==0.1.5
tomlkit==0.11.6
tqdm==4.64.1
types-pytz==2022.6.0.1
typing_extensions==4.4.0
tzdata==2022.6
tzlocal==4.2
ujson==5.5.0
urllib3==1.26.13
uvicorn==0.20.0
uvloop==0.17.0
watchfiles==0.18.1
wcwidth==0.2.5
websockets==10.4
wordcloud==1.8.2.2
yarl==1.8.2
yetanotherpicsearch==1.7.8

如何复现

用附件图片直接搜索,应该能稳定触发异常。(至少在我这里是) 2D 32O`3CLTU9`0{2WMP9SQ

期望行为

No response

实际行为

出错时的聊天截图: image 出错时的日志:

01-03 19:02:58 [ERROR] YetAnotherPicSearch | 该图 [https://gchat.qpic.cn/gchatpic_new/0/0-0-FCF9EC0E7146B98439A271CA7E706640/0] 搜图失败
Traceback (most recent call last):
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/bin/nb", line 8, in <module>
    sys.exit(main())
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nb_cli/commands/main.py", line 30, in run
    run_bot(file, app)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nb_cli/handlers/deploy.py", line 25, in run_bot
    nonebot.run(app=f"{module_name}:{app}")
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/__init__.py", line 273, in run
    get_driver().run(*args, **kwargs)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/drivers/fastapi.py", line 172, in run
    uvicorn.run(
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/uvicorn/main.py", line 569, in run
    server.run()
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/uvicorn/server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/message.py", line 142, in _check_matcher
    await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/message.py", line 188, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 727, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 702, in simple_run
    await handler(
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/dependencies/__init__.py", line 108, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/__init__.py", line 258, in handle_image_search
    await image_search(url, md5, mode, purge, _cache, client),
> File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/__init__.py", line 110, in image_search
    async for attempt in AsyncRetrying(
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/tenacity/_asyncio.py", line 69, in __anext__
    do = self.iter(retry_state=self._retry_state)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/tenacity/__init__.py", line 362, in iter
    raise retry_exc.reraise()
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/tenacity/__init__.py", line 195, in reraise
    raise self.last_attempt.result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/__init__.py", line 123, in image_search
    result = await saucenao_search(url, mode, client, hide_img)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/saucenao.py", line 107, in saucenao_search
    final_res.extend(await ehentai_title_search(selected_res.title, hide_img))
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/ehentai.py", line 50, in ehentai_title_search
    if res := EHentaiResponse(await resp.text(), str(resp.url)):
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/PicImageSearch/model/ehentai.py", line 44, in __init__
    self.raw = [
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/PicImageSearch/model/ehentai.py", line 45, in <listcomp>
    EHentaiItem(i)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/PicImageSearch/model/ehentai.py", line 16, in __init__
    self._arrange(data)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/PicImageSearch/model/ehentai.py", line 27, in _arrange
    if not self.thumbnail.startswith("http"):
AttributeError: 'NoneType' object has no attribute 'startswith'
01-03 19:02:59 [INFO] nonebot | Matcher(type='message', module=YetAnotherPicSearch) running complete

出现问题的图片: 2D 32O`3CLTU9`0{2WMP9SQ

NekoAria commented 1 year ago

请你更新一下 picimagesearch ,之后重启机器人再试试。

Yangleis commented 1 year ago

picimagesearch 更新至 3.7.6 ,重复数次尝试,都是报了了另一个错误。(日志在末尾) image

补充下我的配置情况: image 只配置了SAUCENAO_API_KEY、EXHENTAI_COOKIES两项,其他未配置。

顺带提一下,不知是我QQ号被风控还是QQ对这张图特别敏感,每次搜索完我想再发这张图就发不出去了,每次搜索我都是重新截图的,但基本都是截的全图少一点点像素。

错误日志:

01-04 15:29:14 [ERROR] YetAnotherPicSearch | 该图 [https://gchat.qpic.cn/gchatpic_new/0/0-0-FF919626FF9416CFD6673B6CAC9A559F/0] 搜图失败
Traceback (most recent call last):
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/bin/nb", line 8, in <module>
    sys.exit(main())
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nb_cli/commands/main.py", line 30, in run
    run_bot(file, app)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nb_cli/handlers/deploy.py", line 25, in run_bot
    nonebot.run(app=f"{module_name}:{app}")
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/__init__.py", line 273, in run
    get_driver().run(*args, **kwargs)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/drivers/fastapi.py", line 172, in run
    uvicorn.run(
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/uvicorn/main.py", line 569, in run
    server.run()
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/uvicorn/server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/message.py", line 142, in _check_matcher
    await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/message.py", line 188, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 727, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/internal/matcher/matcher.py", line 702, in simple_r
    await handler(
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/nonebot/dependencies/__init__.py", line 108, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/__init__.py", line 258, in handle_image
    await image_search(url, md5, mode, purge, _cache, client),
> File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/__init__.py", line 110, in image_search
    async for attempt in AsyncRetrying(
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/tenacity/_asyncio.py", line 69, in __anext__
    do = self.iter(retry_state=self._retry_state)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/tenacity/__init__.py", line 362, in iter
    raise retry_exc.reraise()
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/tenacity/__init__.py", line 195, in reraise
    raise self.last_attempt.result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/__init__.py", line 123, in image_search
    result = await saucenao_search(url, mode, client, hide_img)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/saucenao.py", line 107, in saucenao_sea
    final_res.extend(await ehentai_title_search(selected_res.title, hide_img))
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/ehentai.py", line 69, in ehentai_title_
    return await search_result_filter(res, hide_img)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/ehentai.py", line 122, in search_result
    thumbnail = await handle_img(
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/utils.py", line 38, in handle_img
    if image_bytes := await get_image_bytes_by_url(url, cookies):
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/YetAnotherPicSearch/utils.py", line 26, in get_image_bytes_
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/aiohttp/client.py", line 357, in _build_url
    url = URL(str_or_url)
  File "/home/qqbot/.cache/pypoetry/virtualenvs/nonebot-C1Dwp4J_-py3.10/lib/python3.10/site-packages/yarl/_url.py", line 154, in __new__
    raise TypeError("Constructor parameter should be str")
TypeError: Constructor parameter should be str
01-04 15:29:15 [INFO] nonebot | Matcher(type='message', module=YetAnotherPicSearch) running complete
NekoAria commented 1 year ago

麻烦你往本地依赖文件里的 PicImageSearch/model/ehentai.py 第 16 行后面添加下面两行代码:

        from loguru import logger
        logger.info(data)

然后重启机器人,再试着搜索那张图,把这里额外打印的日志贴出来。 主要是我不知道你那边获取到的 EH 网页结构为什么不太一样,所以需要看看。

Yangleis commented 1 year ago

日志内容太多,无法直接放回复里,所以只能上传文件,这只是一次搜索的日志。 nonebot.log

NekoAria commented 1 year ago

我知道为什么了,因为你用的网页布局确实不一样。。 Minimal / Minimal+ / Compact / Extended / Thumbnail ,前三个差别不是很大,后两个和前面的差别比较大。 等我再改改 PicImageSearch 的解析逻辑。

Yangleis commented 1 year ago

看来确实是这个原因,我把布局改为 Compact 就正常了。

NekoAria commented 1 year ago

改好了,你可以用 pip install -U PicImageSearch 来更新依赖。