KomoriDev / nonebot_plugin_og

检测链接并发送网站简介及预览图
MIT License
7 stars 0 forks source link

插件输出异常 #4

Open ABKQPO opened 1 year ago

ABKQPO commented 1 year ago

07-30 00:11:30 [ERROR] nonebot | Running Matcher(type='message', module=nonebot_plugin_og) failed. Traceback (most recent call last): File "D:\NoneBot\ABK.venv\lib\site-packages\pyquery\pyquery.py", line 59, in fromstring result = getattr(etree, meth)(context) File "src\lxml\etree.pyx", line 3257, in lxml.etree.fromstring File "src\lxml\parser.pxi", line 1916, in lxml.etree._parseMemoryDocument File "src\lxml\parser.pxi", line 1803, in lxml.etree._parseDoc File "src\lxml\parser.pxi", line 1144, in lxml.etree._BaseParser._parseDoc File "src\lxml\parser.pxi", line 618, in lxml.etree._ParserContext._handleParseResultDoc File "src\lxml\parser.pxi", line 728, in lxml.etree._handleParseResult File "src\lxml\parser.pxi", line 657, in lxml.etree._raiseParseError File "", line 1 lxml.etree.XMLSyntaxError: Document is empty, line 1, column 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\NoneBot\ABK\bot.py", line 21, in nonebot.run() File "D:\NoneBot\ABK.venv\lib\site-packages\nonebot__init__.py", line 309, in run get_driver().run(*args, *kwargs) File "D:\NoneBot\ABK.venv\lib\site-packages\nonebot\drivers\fastapi.py", line 198, in run uvicorn.run( File "D:\NoneBot\ABK.venv\lib\site-packages\uvicorn\main.py", line 578, in run server.run() File "D:\NoneBot\ABK.venv\lib\site-packages\uvicorn\server.py", line 61, 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 636, 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 603, in run_forever self._run_once() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1909, 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 "D:\NoneBot\ABK.venv\lib\site-packages\nonebot\message.py", line 467, in check_and_run_matcher await _run_matcher(

File "D:\NoneBot\ABK.venv\lib\site-packages\nonebot\message.py", line 419, in _run_matcher await matcher.run(bot, event, state, stack, dependency_cache) File "D:\NoneBot\ABK.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 753, in run await self.simple_run(bot, event, state, stack, dependency_cache) File "D:\NoneBot\ABK.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 728, in simple_run await handler( File "D:\NoneBot\ABK.venv\lib\site-packages\nonebot\dependencies__init.py", line 108, in call return await cast(Callable[..., Awaitable[R]], self.call)(values) File "D:\NoneBot\ABK.venv\lib\site-packages\nonebot_plugin_og__init.py", line 21, in get_og og_info = await get_og_info(event.message) File "D:\NoneBot\ABK.venv\lib\site-packages\nonebot_plugin_og\utils.py", line 13, in get_og_info doc = pq(res.content) File "D:\NoneBot\ABK.venv\lib\site-packages\pyquery\pyquery.py", line 212, in init elements = fromstring(context, self.parser) File "D:\NoneBot\ABK.venv\lib\site-packages\pyquery\pyquery.py", line 63, in fromstring result = getattr(lxml.html, meth)(context) File "D:\NoneBot\ABK.venv\lib\site-packages\lxml\html\init__.py", line 873, in fromstring doc = document_fromstring(html, parser=parser, base_url=base_url, kw) File "D:\NoneBot\ABK.venv\lib\site-packages\lxml\html\init__.py", line 761, in document_fromstring raise etree.ParserError( lxml.etree.ParserError: Document is empty

KomoriDev commented 1 year ago

怪,这插件我自己都没怎么用,刚下载下来是可以用的,你能为我讲述下你的复现步骤吗? image

KomoriDev commented 1 year ago

我刚发现代码的一个小问题,但其实当我测试后发现它并不影响使用: startswith 是一个字符串的方法,但是它不能直接应用于 PyQuery 对象 https://github.com/KomoriDev/nonebot_plugin_og/blob/17e172e86eb42624398c64bb317aff5ca24b5c58/nonebot_plugin_og/utils.py#L20-L21 您可以先将 20 行改为 property_name = str(tag.attr("property")) 后再次尝试

ABKQPO commented 1 year ago

当我私信发送bot链接(如https://cn.bing.com)以后控制台会立刻出现报错,但是发送一些别的链接虽然没有报错但是插件并没有返回任何信息

KomoriDev commented 1 year ago

emm....可能只支持部分链接(? 整不会了

Arasi2333 commented 1 year ago

emm....可能只支持部分链接(? 整不会了

看起来是的,我发送github之类的网站就正常输出,baidu.com就报如下错误 Traceback (most recent call last): File "", line 17, in File "/root/Arasi/.venv/lib/python3.11/site-packages/nonebot/init.py", line 333, in run get_driver().run(*args, **kwargs) File "/root/Arasi/.venv/lib/python3.11/site-packages/nonebot/drivers/fastapi.py", line 199, in run uvicorn.run( File "/root/Arasi/.venv/lib/python3.11/site-packages/uvicorn/main.py", line 587, in run server.run() File "/root/Arasi/.venv/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 "/root/Arasi/.venv/lib/python3.11/site-packages/nonebot/message.py", line 467, in check_and_run_matcher await _run_matcher(

File "/root/Arasi/.venv/lib/python3.11/site-packages/nonebot/message.py", line 419, in _run_matcher await matcher.run(bot, event, state, stack, dependency_cache) File "/root/Arasi/.venv/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 759, in run await self.simple_run(bot, event, state, stack, dependency_cache) File "/root/Arasi/.venv/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 734, in simple_run await handler( File "/root/Arasi/.venv/lib/python3.11/site-packages/nonebot/dependencies/init.py", line 108, in call return await cast(Callable[..., Awaitable[R]], self.call)(values) File "/root/Arasi/.venv/lib/python3.11/site-packages/nonebot_plugin_og/init.py", line 21, in get_og og_info = await get_og_info(event.message) File "/root/Arasi/.venv/lib/python3.11/site-packages/nonebot_plugin_og/utils.py", line 12, in get_og_info res = await client.get(url.group()) File "/root/Arasi/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1757, in get return await self.request( File "/root/Arasi/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1530, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) File "/root/Arasi/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1617, in send response = await self._send_handling_auth( File "/root/Arasi/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1645, in _send_handling_auth response = await self._send_handling_redirects( File "/root/Arasi/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects response = await self._send_single_request(request) File "/root/Arasi/.venv/lib/python3.11/site-packages/httpx/_client.py", line 1719, in _send_single_request response = await transport.handle_async_request(request) File "/root/Arasi/.venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 353, in handle_async_request resp = await self._pool.handle_async_request(req) File "/root/Arasi/.venv/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request raise exc File "/root/Arasi/.venv/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request response = await connection.handle_async_request(request) File "/root/Arasi/.venv/lib/python3.11/site-packages/httpcore/_async/http_proxy.py", line 289, in handle_async_request stream = await stream.start_tls(kwargs) File "/root/Arasi/.venv/lib/python3.11/site-packages/httpcore/backends/asyncio.py", line 78, in start_tls raise exc File "/root/Arasi/.venv/lib/python3.11/site-packages/httpcore/backends/asyncio.py", line 69, in start_tls ssl_stream = await anyio.streams.tls.TLSStream.wrap( File "/root/Arasi/.venv/lib/python3.11/site-packages/anyio/streams/tls.py", line 123, in wrap await wrapper._call_sslobject_method(ssl_object.do_handshake) File "/root/Arasi/.venv/lib/python3.11/site-packages/anyio/streams/tls.py", line 131, in _call_sslobject_method result = func(*args) File "/usr/lib/python3.11/ssl.py", line 979, in do_handshake self._sslobj.do_handshake() ssl.SSLZeroReturnError: TLS/SSL connection has been closed (EOF) (_ssl.c:992)

KomoriDev commented 1 year ago