synodriver / nonebot_plugin_picsearcher

pic search plugin for nonebot2
GNU General Public License v3.0
111 stars 17 forks source link

使用手机发送的图片会报错 #64

Open Kinray7 opened 1 month ago

Kinray7 commented 1 month ago

如题,报错可能与服务器的SSL证书有关。服务器可能使用了过期或无效的证书,或在客户端和服务器之间存在SSL版本的不匹配问题。Python的SSL库未能成功完成握手,因此出现了错误。

Traceback (most recent call last): File "F:_Nai\NoneBot\tester.venv\lib\site-packages\aiohttp\connector.py", line 1080, in _wrap_create_connection return await self._loop.create_connection(*args, **kwargs, sock=sock) File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 1089, in create_connection transport, protocol = await self._create_connection_transport( File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 1119, in _create_connection_transport await waiter File "C:\Program Files\Python310\lib\asyncio\sslproto.py", line 534, in data_received ssldata, appdata = self._sslpipe.feed_ssldata(data) File "C:\Program Files\Python310\lib\asyncio\sslproto.py", line 188, in feed_ssldata self._sslobj.do_handshake() File "C:\Program Files\Python310\lib\ssl.py", line 975, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "F:_Nai\NoneBot\tester.venv\lib\site-packages\nonebot_plugin_picsearcher__init.py", line 86, in get_setu msgs = [msg if isinstance(msg, Message) else Message(msg) async for msg in get_des(url, mod)] File "F:_Nai\NoneBot\tester.venv\lib\site-packages\nonebot_plugin_picsearcher__init.py", line 86, in msgs = [msg if isinstance(msg, Message) else Message(msg) async for msg in get_des(url, mod)] File "F:_Nai\NoneBot\tester.venv\lib\site-packages\nonebot_plugin_picsearcher\init__.py", line 51, in get_des async for msg in get_des_sau(url): File "F:_Nai\NoneBot\tester.venv\lib\site-packages\nonebot_plugin_picsearcher\saucenao.py", line 84, in get_des image_data: List[Tuple] = await get_pic_from_url(url) File "F:_Nai\NoneBot\tester.venv\lib\site-packages\nonebot_plugin_picsearcher\saucenao.py", line 72, in get_pic_from_url async with session.get(url) as resp: File "F:_Nai\NoneBot\tester.venv\lib\site-packages\aiohttp\client.py", line 1353, in aenter__ self._resp = await self._coro File "F:_Nai\NoneBot\tester.venv\lib\site-packages\aiohttp\client.py", line 657, in _request conn = await self._connector.connect( File "F:_Nai\NoneBot\tester.venv\lib\site-packages\aiohttp\connector.py", line 564, in connect proto = await self._create_connection(req, traces, timeout) File "F:_Nai\NoneBot\tester.venv\lib\site-packages\aiohttp\connector.py", line 975, in _createconnection , proto = await self._create_direct_connection(req, traces, timeout) File "F:_Nai\NoneBot\tester.venv\lib\site-packages\aiohttp\connector.py", line 1350, in _create_direct_connection raise last_exc File "F:_Nai\NoneBot\tester.venv\lib\site-packages\aiohttp\connector.py", line 1319, in _create_direct_connection transp, proto = await self._wrap_create_connection( File "F:_Nai\NoneBot\tester.venv\lib\site-packages\aiohttp\connector.py", line 1084, in _wrap_create_connection raise ClientConnectorSSLError(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorSSLError: Cannot connect to host multimedia.nt.qq.com.cn:443 ssl:default [[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:997)]

Kinray7 commented 1 month ago

电脑使用是完全正常的

synodriver commented 1 month ago

好神奇的报错……

synodriver commented 1 month ago

服务器的py是什么版本的?从哪安装的?

barryblueice commented 3 weeks ago

我也遇到了这个问题,貌似和aiohttp有关。 而且不只是移动端,桌面端也会出现这个问题。 根据报错判断应该是腾讯的锅。 目前暂时的解决方法是用httpx方法替代原来的aiohttp.get方法。 将saucenao.py第85行开始:

async with session.get(url) as resp:
     content = io.BytesIO(await resp.read())

改成:

import httpx

async with httpx.AsyncClient(verify=True) as client:
     response = await client.get(url)
     content = io.BytesIO(response.content)

即可正常使用。 目前暂未出现问题。

image

barryblueice commented 3 weeks ago

并且并不只是saucenao.py有这个问题,其他方法也会有相同问题,修改方法基本是一样的。 目前已知saucenao、ex、trace、iqdb都有这个问题。

synodriver commented 3 days ago

怪哉,aiohttp抽风?更新下aiohttp呢?

barryblueice commented 3 days ago

怪哉,aiohttp抽风?更新下aiohttp呢?

我用的就是最新的aiohttp,问题是一样的,貌似是因为ssl版本协议问题,只能用httpx,之前写其他插件的时候遇到过

synodriver commented 3 days ago

httpx和aiohttp都是用的标准库的ssl库,怎么可能aiohttp出事而httpx正常呢……等下我试试那个curl库,它的ssl是boringssl