-
请确保您已阅读以上注意事项,并勾选下方的确认框。
Lagrange项目OneBot 所使用/依赖的Lagrange项目对应的commit运行环境Linux 运行架构x64 连接方式反向 WebSocket 重现步骤使用 nonebot.adapters.onebot.v11 发送图片时报错 期望的结果是什么?能够正常发送图片.并且不会再次执行上传图片的行为 实际的结果是什么?简单的复现代码/链接(可选)# 框架规则
from nonebot import on_command
# 通讯协议
from nonebot.adapters.onebot.v11 import MessageSegment
# 随机图片
image = on_command('随机图片')
@image.handle()
async def _():
url = 'https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=CgozMjk2MTMyNjUxEhTB9IpgDFjncZODQma9FBjGqwpbshjOkZEBIP8KKMmI2cWLwYUDUIC9owE&rkey=CAQSMLhE1BzKB7G4ezEtcO-3ZHqMrrDifo2LG1uDFAQqKmt_fSXf_tw4XCUmD6TeiQGDyg&spec=0'
await image.send(MessageSegment.image(url))
await image.finish() 日志记录(可选)info: Lagrange.Core.BotContext[0]
[2024-04-14 14:39:56] [MessagingLogic] [VERBOSE]: [MessageChain(761290459)(3218366812)] [Text]: 随机图片trce: Lagrange.OneBot.Core.Network.Service.ReverseWSService[1]
[ReverseWSService] Send: {"message_type":"group","sub_type":"normal","message_id":93102705,"group_id":761290459,"user_id":3218366812,"anonymous":null,"message":[{"type":"text","data":{"text":"\u968F\u673A\u56FE\u7247"}}],"raw_message":"\u968F\u673A\u56FE\u7247","font":0,"sender":{"user_id":3218366812,"nickname":"\u96EA\u5154","card":"","sex":"unknown","age":0,"area":"","level":"83","role":"owner","title":""},"time":1713076796,"self_id":3296132651,"post_type":"message"}
trce: Lagrange.OneBot.Core.Network.Service.ReverseWSService[2]
[ReverseWSService] Receive: {"action": "send_msg", "params": {"user_id": 3218366812, "group_id": 761290459, "message_type": "group", "message": [{"type": "image", "data": {"file": "https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=CgozMjk2MTMyNjUxEhTB9IpgDFjncZODQma9FBjGqwpbshjOkZEBIP8KKMmI2cWLwYUDUIC9owE&rkey=CAQSMLhE1BzKB7G4ezEtcO-3ZHqMrrDifo2LG1uDFAQqKmt_fSXf_tw4XCUmD6TeiQGDyg&spec=0", "type": null, "cache": "true", "proxy": "true", "timeout": null}}]}, "echo": "1"}
warn: Lagrange.OneBot.Core.Operation.OperationService[0]
Unexpected error encountered while handling message.
System.AggregateException: One or more errors occurred. (The SSL connection could not be established, see inner exception.)
---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> Interop+OpenSsl+SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
---> Interop+Crypto+OpenSslCryptographicException: error:0A000410:SSL routines::sslv3 alert handshake failure
--- End of inner exception stack trace ---
at Interop.OpenSsl.DoSslHandshake(SafeSslHandle context, ReadOnlySpan`1 input, Byte[]& sendBuf, Int32& sendCount)
at System.Net.Security.SslStreamPal.HandshakeInternal(SafeDeleteSslContext& context, ReadOnlySpan`1 inputBuffer, Byte[]& outputBuffer, SslAuthenticationOptions sslAuthenticationOptions)
--- End of inner exception stack trace ---
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken)
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem)
at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Lagrange.OneBot.Message.Entity.CommonResolver.ResolveStream(String url)
at Lagrange.OneBot.Message.Entity.ImageSegment.Build(MessageBuilder builder, SegmentBase segment)
at Lagrange.OneBot.Core.Operation.Message.MessageCommon.BuildMessages(MessageBuilder builder, List`1 segments)
at Lagrange.OneBot.Core.Operation.Message.MessageCommon.ParseChain(OneBotMessage message)
at Lagrange.OneBot.Core.Operation.Message.SendMessageOperation.HandleOperation(BotContext context, JsonNode payload)
at Lagrange.OneBot.Core.Operation.OperationService.HandleOperation(MsgRecvEventArgs e)
trce: Lagrange.OneBot.Core.Network.Service.ReverseWSService[1]
[ReverseWSService] Send: {"status":"failed","retcode":200,"data":null,"echo":"1"}
trce: Lagrange.Core.BotContext[0]
[2024-04-14 14:39:58] [ServiceContext] [DEBUG]: Outgoing SSOFrame: Heartbeat.Alive
trce: Lagrange.OneBot.Core.Network.Service.ReverseWSService[1]
[ReverseWSService] Send: {"interval":5000,"status":{"app_initialized":true,"app_enabled":true,"app_good":true,"online":true,"good":true},"meta_event_type":"heartbeat","time":1713076799,"self_id":3296132651,"post_type":"meta_event"}
trce: Lagrange.OneBot.Core.Network.Service.ReverseWSService[1]
[ReverseWSService] Send: {"interval":5000,"status":{"app_initialized":true,"app_enabled":true,"app_good":true,"online":true,"good":true},"meta_event_type":"heartbeat","time":1713076804,"self_id":3296132651,"post_type":"meta_event"}
trce: Lagrange.Core.BotContext[0] 补充说明(可选)No response |
Beta Was this translation helpful? Give feedback.
Replies: 17 comments
-
无法复现 |
Beta Was this translation helpful? Give feedback.
-
遇到类似问题,其他图片都可以发送,这个域名的图片均无法发送 复现步骤 日志记录
|
Beta Was this translation helpful? Give feedback.
-
linux版本无法发送,win版本能正常发送 https://view.nicemoe.cn/static/dde706d9f40176020ffa26eb30306d3a62d378cb243af4daae83c9a6d9ef72a7.jpg |
Beta Was this translation helpful? Give feedback.
-
你试试在你的linux机器上能不能用wget/curl下载这个图片 |
Beta Was this translation helpful? Give feedback.
-
root@ls: curl能下载成功 |
Beta Was this translation helpful? Give feedback.
-
报错还是这个嘛 |
Beta Was this translation helpful? Give feedback.
-
是的,在win版本可以,在linux就不行 |
Beta Was this translation helpful? Give feedback.
-
只有这张图发不出去?还是只要用了这个域名都发不出去 |
Beta Was this translation helpful? Give feedback.
-
这个域名下的都发不出去,其他HTTPS域名的能正常发 |
Beta Was this translation helpful? Give feedback.
-
问题是这张图浏览器都打不开哇,图链本身有问题 |
Beta Was this translation helpful? Give feedback.
-
https://view.nicemoe.cn/static/dde706d9f40176020ffa26eb30306d3a62d378cb243af4daae83c9a6d9ef72a7.jpg |
Beta Was this translation helpful? Give feedback.
-
破案了,trustaisa证书有问题,那玩意很多浏览器不信的,国产证书就这个样子,如果可以不走ssl的话就不走,不然就得自己去搞定这个证书 |
Beta Was this translation helpful? Give feedback.
-
哈哈我就知道() |
Beta Was this translation helpful? Give feedback.
-
+1 复现步骤使用 nonebot2, 配置 from nonebot import on_message, get_driver
from nonebot.drivers import Request
from nonebot.adapters.onebot.v11 import MessageEvent
@on_message().handle()
async def _(event: MessageEvent):
for seg in event.get_message():
if seg.type == 'image':
print(await get_driver().request(setup=Request(method='GET', url=seg.data.get('url')))) 发送任意图片 05-26 00:57:43 [SUCCESS] nonebot | OneBot V11 xxx | [message.group.normal]: Message 21432191 from xxx@[群:xxx] '[image:file=https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=Cgk2MjUz...,url=https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=Cgk2MjUz...,summary=[动画表情]]'
05-26 00:57:43 [DEBUG] nonebot | Checking for matchers in priority 1...
05-26 00:57:43 [INFO] nonebot | Event will be handled by Matcher(type='message', module=test.v2.ntqq_image, lineno=17)
05-26 00:57:43 [DEBUG] nonebot | Running Matcher(type='message', module=test.v2.ntqq_image, lineno=17)
05-26 00:57:43 [DEBUG] nonebot | Running handler Dependent(call=_)
05-26 00:57:45 [INFO] nonebot | Matcher(type='message', module=test.v2.ntqq_image, lineno=17) running complete
05-26 00:57:45 [ERROR] nonebot | Running Matcher(type='message', module=test.v2.ntqq_image, lineno=17) failed.
Traceback (most recent call last):
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\aiohttp\connector.py", line 1025, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs)
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1113, in create_connection
transport, protocol = await self._create_connection_transport(
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1146, in _create_connection_transport
await waiter
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\sslproto.py", line 578, in _on_handshake_complete
raise handshake_exc
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\sslproto.py", line 560, in _do_handshake
self._sslobj.do_handshake()
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 979, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1006)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\bot.py", line 70, in <module>
nonebot.run()
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\nonebot\__init__.py", line 335, in run
get_driver().run(*args, **kwargs)
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\nonebot\drivers\fastapi.py", line 186, in run
uvicorn.run(
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\uvicorn\main.py", line 575, in run
server.run()
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\uvicorn\server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 641, in run_until_complete
self.run_forever()
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 321, in run_forever
super().run_forever()
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 608, in run_forever
self._run_once()
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1936, in _run_once
handle._run()
File "C:\Users\Ailit\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 84, in _run
self._context.run(self._callback, *self._args)
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\nonebot\message.py", line 476, in check_and_run_matcher
await _run_matcher(
> File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\nonebot\message.py", line 428, in _run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 850, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 825, in simple_run
await handler(
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\nonebot\dependencies\__init__.py", line 94, in __call__
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\test\v2\ntqq_image.py", line 21, in _
print(await get_driver().request(setup=Request(method='GET', url=seg.data.get('url'))))
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\nonebot\drivers\aiohttp.py", line 159, in request
return await session.request(setup)
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\nonebot\drivers\aiohttp.py", line 109, in request
async with await self.client.request(
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\aiohttp\client.py", line 581, in _request
conn = await self._connector.connect(
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\aiohttp\connector.py", line 544, in connect
proto = await self._create_connection(req, traces, timeout)
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\aiohttp\connector.py", line 944, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\aiohttp\connector.py", line 1257, in _create_direct_connection
raise last_exc
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\aiohttp\connector.py", line 1226, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "C:\Users\Ailit\PycharmProjects\nonebot2_miya\venv\Lib\site-packages\aiohttp\connector.py", line 1029, 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:1006)]
05-26 00:57:45 [DEBUG] nonebot | Stop event propagation
05-26 00:57:45 [DEBUG] nonebot | Checking for matchers completed |
Beta Was this translation helpful? Give feedback.
-
aiohttp的话,不介意的话可以使用http拉取 可以参考下我的修改:https://gist.github.com/pk5ls20/a2ded67daf09b38458d7d56e4c30b53f |
Beta Was this translation helpful? Give feedback.
-
只用 import ssl
import socket
def verify_ssl(hostname: str, port: int = 443):
context = ssl.create_default_context()
context.set_ciphers('AES')
with socket.create_connection((hostname, port)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
print(ssock.cipher())
print(ssock.version())
verify_ssl('multimedia.nt.qq.com.cn') 通过
|
Beta Was this translation helpful? Give feedback.
-
省流 x1:NoneBot2用户可以使用 NoneBot插件 lgc-NB2Dev/nonebot-plugin-fix-qq-img-ssl 进行修复 省流 x2:Python 的 httpx(>=0.28.0) 解决方案可以参考 https://github.com/Moemu/MuiceBot/pull/4/files 省流 x3:其他语言的 http client 实现的问题解决方案可以阅读下文后探索自行实现 今天有群友又提到了这个问题,回去看了下,真正的问题应该是ssl握手阶段,客户端和服务器端的密码套件对不上 左面的是客户端(aiohttp/requests/urllib3,使用的都是ssl模块的默认密码套件),右面的是 在我这里, 由于 aiohttp, requests, urllib3 默认情况下不修改ssl模块使用的加密套件1 2 3,但是 httpx(版本 < 0.28.0) 在导入ssl模块后还会修改密码套件4,所以使用httpx(版本 < 0.28.0)可以直接请求 Footnotes |
Beta Was this translation helpful? Give feedback.
省流 x1:
NoneBot2用户可以使用 NoneBot插件 lgc-NB2Dev/nonebot-plu…