project-mirai / mirai-api-http

Mirai HTTP API (console) plugin
GNU Affero General Public License v3.0
1.66k stars 343 forks source link

请问 V2.10.0 ws 报错 #759

Open gebederry opened 8 months ago

gebederry commented 8 months ago

使用的版本

问题描述

V2.9.1 无问题,V2.10.0 报错如下

使用 Node.js/mirai-ts/mirai-js 作为客户端

MAH 的报错 错误日志输出会伴随每一条监听的消息一同报出。

2024-02-11 20:53:41 E/Mah Debug: java.util.concurrent.CancellationException: ArrayChannel was cancelled
java.util.concurrent.CancellationException: ArrayChannel was cancelled
    at kotlinx.coroutines.channels.AbstractChannel.cancel(AbstractChannel.kt:656)
    at kotlinx.coroutines.channels.ReceiveChannel$DefaultImpls.cancel$default(Channel.kt:279)
    at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.websocket.DefaultWebSocketSessionImpl$runOutgoingProcessor$1.invokeSuspend(DefaultWebSocketSession.kt:228)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:69)
    at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:245)
    at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161)
    at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
    at kotlinx.coroutines.CancellableContinuationImpl.completeResume(CancellableContinuationImpl.kt:513)
    at kotlinx.coroutines.channels.AbstractChannel$ReceiveHasNext.resumeReceiveClosed(AbstractChannel.kt:958)
    at kotlinx.coroutines.channels.AbstractSendChannel.helpClose(AbstractChannel.kt:342)
    at kotlinx.coroutines.channels.AbstractSendChannel.close(AbstractChannel.kt:271)
    at kotlinx.coroutines.channels.SendChannel$DefaultImpls.close$default(Channel.kt:93)
    at mirai-api-http-2.10.0.mirai2.jar[shared]//io.ktor.websocket.RawWebSocketJvm$1.invokeSuspend(RawWebSocketJvm.kt:78)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)

客户端 mirai-ts/mirai-js 的报错 MobaXterm_8ZFavBIzvr

MobaXterm_Alm33ggSgT

ws 库中的相关代码

    const secWebSocketExtensions = res.headers['sec-websocket-extensions'];

    if (secWebSocketExtensions !== undefined) {
      if (!perMessageDeflate) {
        const message =
          'Server sent a Sec-WebSocket-Extensions header but no extension ' +
          'was requested';
        abortHandshake(websocket, socket, message);
        return;
      }

      let extensions;

      try {
        extensions = parse(secWebSocketExtensions);
      } catch (err) {
        const message = 'Invalid Sec-WebSocket-Extensions header';
        abortHandshake(websocket, socket, message);
        return;
      }

      const extensionNames = Object.keys(extensions);

      if (
        extensionNames.length !== 1 ||
        extensionNames[0] !== PerMessageDeflate.extensionName
      ) {
        const message = 'Server indicated an extension that was not requested';
        abortHandshake(websocket, socket, message);
        return;
      }

      try {
        perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
      } catch (err) {
        const message = 'Invalid Sec-WebSocket-Extensions header';
        abortHandshake(websocket, socket, message);
        return;
      }

      websocket._extensions[PerMessageDeflate.extensionName] =
        perMessageDeflate;
    }

使用 YiriMirai 作为客户端

MAH 无错误输出 客户端 YiriMirai 的报错

[2024-03-08 11:19:50.505] base.py (43) - [ERROR] :
Traceback (most recent call last):
  File "/root/qchatgpt/lib/python3.11/site-packages/websockets/legacy/client.py", line 654, in __await_impl__
    await protocol.handshake(
  File "/root/qchatgpt/lib/python3.11/site-packages/websockets/legacy/client.py", line 325, in handshake
    raise InvalidStatusCode(status_code, response_headers)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 404

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/qchatgpt/lib/python3.11/site-packages/websockets/legacy/client.py", line 647, in __await_impl_timeout__
    return await self.__await_impl__()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/qchatgpt/lib/python3.11/site-packages/websockets/legacy/client.py", line 668, in __await_impl__
    await protocol.wait_closed()
asyncio.exceptions.CancelledError

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

Traceback (most recent call last):
  File "/opt/apps/qchatgpt/main.py", line 287, in run_bot_wrapper
    qqbot.adapter.run_sync()
  File "/opt/apps/qchatgpt/pkg/qqbot/sources/yirimirai.py", line 120, in run_sync
    loop.run_until_complete(MiraiRunner(self.bot)._run())
  File "/root/.pyenv/versions/3.11.7/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/root/qchatgpt/lib/python3.11/site-packages/mirai/bot.py", line 240, in _run
    await self.startup()
  File "/root/qchatgpt/lib/python3.11/site-packages/mirai/bot.py", line 228, in startup
    await asyncio.gather(*coros)
  File "/root/qchatgpt/lib/python3.11/site-packages/mirai/bot.py", line 137, in startup
    await self._adapter.login(self.qq)
  File "/root/qchatgpt/lib/python3.11/site-packages/mirai/adapters/base.py", line 35, in wrapped
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/qchatgpt/lib/python3.11/site-packages/mirai/adapters/websocket.py", line 187, in login
    self.connection = await connect(self.host_name, extra_headers=headers)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/qchatgpt/lib/python3.11/site-packages/websockets/legacy/client.py", line 646, in __await_impl_timeout__
    async with asyncio_timeout(self.open_timeout):
  File "/root/.pyenv/versions/3.11.7/lib/python3.11/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError
[2024-03-08 11:19:50.509] main.py (324) - [ERROR] : 捕捉到未知异常:, 请前往 https://github.com/RockChinQ/QChatGPT/issues 查找或提issue
Exception in thread Thread-2 (run_bot_wrapper):
Traceback (most recent call last):
  File "/root/qchatgpt/lib/python3.11/site-packages/websockets/legacy/client.py", line 654, in __await_impl__
    await protocol.handshake(
  File "/root/qchatgpt/lib/python3.11/site-packages/websockets/legacy/client.py", line 325, in handshake
    raise InvalidStatusCode(status_code, response_headers)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 404

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/qchatgpt/lib/python3.11/site-packages/websockets/legacy/client.py", line 647, in __await_impl_timeout__
    return await self.__await_impl__()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/qchatgpt/lib/python3.11/site-packages/websockets/legacy/client.py", line 668, in __await_impl__
    await protocol.wait_closed()
asyncio.exceptions.CancelledError

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

Traceback (most recent call last):
  File "/root/.pyenv/versions/3.11.7/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "/root/.pyenv/versions/3.11.7/lib/python3.11/threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/apps/qchatgpt/main.py", line 327, in run_bot_wrapper
    raise e
  File "/opt/apps/qchatgpt/main.py", line 287, in run_bot_wrapper
    qqbot.adapter.run_sync()
  File "/opt/apps/qchatgpt/pkg/qqbot/sources/yirimirai.py", line 120, in run_sync
    loop.run_until_complete(MiraiRunner(self.bot)._run())
  File "/root/.pyenv/versions/3.11.7/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/root/qchatgpt/lib/python3.11/site-packages/mirai/bot.py", line 240, in _run
    await self.startup()
  File "/root/qchatgpt/lib/python3.11/site-packages/mirai/bot.py", line 228, in startup
    await asyncio.gather(*coros)
  File "/root/qchatgpt/lib/python3.11/site-packages/mirai/bot.py", line 137, in startup
    await self._adapter.login(self.qq)
  File "/root/qchatgpt/lib/python3.11/site-packages/mirai/adapters/base.py", line 35, in wrapped
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/qchatgpt/lib/python3.11/site-packages/mirai/adapters/websocket.py", line 187, in login
    self.connection = await connect(self.host_name, extra_headers=headers)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/qchatgpt/lib/python3.11/site-packages/websockets/legacy/client.py", line 646, in __await_impl_timeout__
    async with asyncio_timeout(self.open_timeout):
  File "/root/.pyenv/versions/3.11.7/lib/python3.11/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

相关 issues/commits

https://github.com/project-mirai/mirai-api-http/commit/42e528107500f3f7b03dc5947ef852a5651228d5 https://github.com/YunYouJun/mirai-ts/issues/60#issuecomment-1965962979

gebederry commented 7 months ago

急需发送视频的功能,搓了半天没搞定, 发现另一位大佬 MrXiaoM 有过 PR https://github.com/project-mirai/mirai-api-http/pull/748 ,跟到了分支 https://github.com/MrXiaoM/mirai-api-http/tree/video-support 构建了一下可以用了 😄 在 2.9.1 的基础上增加了短视频发送支持。版本号定 2.9.2,有需求的可以下载。 mirai-api-http-2.9.2.mirai2.zip