Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Unexpected server response: 404 #124

Closed
BobH233 opened this issue Dec 30, 2021 · 7 comments
Closed

Error: Unexpected server response: 404 #124

BobH233 opened this issue Dec 30, 2021 · 7 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@BobH233
Copy link

BobH233 commented Dec 30, 2021

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: Unexpected server response: 404
    at ClientRequest.req.on (D:\Coding\BobHBot\node_modules\ws\lib\websocket.js:728:7)
    at ClientRequest.emit (events.js:198:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
    at Socket.socketOnData (_http_client.js:442:20)
    at Socket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:94:17)
Emitted 'error' event at:
    at abortHandshake (D:\Coding\BobHBot\node_modules\ws\lib\websocket.js:896:15)
    at ClientRequest.req.on (D:\Coding\BobHBot\node_modules\ws\lib\websocket.js:728:7)
    [... lines matching original stack trace ...]
    at Socket.Readable.push (_stream_readable.js:224:10)

在发过一条消息过后,报错,之后无法发送消息
代码:

const { Bot,Message } = require('mirai-js');
const bot = new Bot();

async function Main(){
    // 连接到一个 mirai-api-http 服务
    await bot.open({
        baseUrl: 'http://127.0.0.1:2003',
        verifyKey: '[key]',
        // 要绑定的 qq,须确保该用户已在 mirai-console 登录
        qq: 2400006639,
    });

    console.log("connected!");

    await bot.sendMessage({
        friend: '1550000009',
        // Message 实例,表示一条消息
        message: new Message().addText('hello world!')
    });

    await bot.sendMessage({
        // 群号
        group: '580000000',
        // 是 http server 接口所需的原始格式,若提供则优先使用
        message: [
         { type: 'Plain', text: '1234'},
         { type: 'Image', url:'[URL]'}
     ],
    });

    await bot.close();
}

Main();
@Drincann Drincann added the bug Something isn't working label Dec 30, 2021
@Drincann
Copy link
Owner

麻烦提供一下 mirai-api-http 和 mirai-js 的版本号,以及 mirai-api-http 的配置文件。

@Drincann Drincann self-assigned this Dec 30, 2021
@Drincann
Copy link
Owner

尝试 POST /sendFriendMessage 来定位问题,不需要带参数,看一下 status code 是 404 还是 400。

@BobH233
Copy link
Author

BobH233 commented Dec 31, 2021

已解决,原因是配置文件中未开启websocket,我以为http和ws只需要二选一即可

@BobH233 BobH233 closed this as completed Dec 31, 2021
@Drincann Drincann added good first issue Good for newcomers and removed bug Something isn't working labels Dec 31, 2021
@Drincann
Copy link
Owner

是的,需要开启 http 和 ws 这两个 adaptor。

@BobH233
Copy link
Author

BobH233 commented Dec 31, 2021

是的,需要开启 http 和 ws 这两个 adaptor。

我还有个问题,在bot.open中只设置了http端口,假如ws端口和http端口不一致,miral-js是如何确定ws端口并连接的呢?

@Drincann
Copy link
Owner

是的,需要开启 http 和 ws 这两个 adaptor。

我还有个问题,在bot.open中只设置了http端口,假如ws端口和http端口不一致,miral-js是如何确定ws端口并连接的呢?

没有相关的处理,这是因为 mirai-api-http v1.x 中并没有 adaptor 的概念,ws 和 http 默认开放在同一个端口。

在 mirai-js 适配 v2.x 时,没有做改动。

如果要分开,为了将来的扩展性,可能要重新抽象一些东西。

@BobH233
Copy link
Author

BobH233 commented Dec 31, 2021

是的,需要开启 http 和 ws 这两个 adaptor。

我还有个问题,在bot.open中只设置了http端口,假如ws端口和http端口不一致,miral-js是如何确定ws端口并连接的呢?

没有相关的处理,这是因为 mirai-api-http v1.x 中并没有 adaptor 的概念,ws 和 http 默认开放在同一个端口。

在 mirai-js 适配 v2.x 时,没有做改动。

如果要分开,为了将来的扩展性,可能要重新抽象一些东西。

好的

@Drincann Drincann reopened this Jan 4, 2022
@Drincann Drincann pinned this issue Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants