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

[Bug] 发送消息时提示 502 #15

Open
3 tasks done
SofiaXu opened this issue Oct 2, 2023 · 15 comments
Open
3 tasks done

[Bug] 发送消息时提示 502 #15

SofiaXu opened this issue Oct 2, 2023 · 15 comments
Labels
bug Something isn't working

Comments

@SofiaXu
Copy link

SofiaXu commented Oct 2, 2023

请确认:

  • 问题的标题明确
  • 我翻阅过其他的 issue 并且找不到类似的问题
  • 我已经阅读了相关文档 并仍然认为这是一个Bug

Bug

问题

在 Bot 发送消息时出现 Unauthorized,接收消息正常

如何复现

预期行为

使用环境:

  • 操作系统 (Windows/Linux/Mac): Windows
  • Python 版本: 3.9
  • Nonebot2 版本: 2.1.1 Red: 0.5.1
  • Chronocat 版本: 0.0.48
  • 是否使用 BetterQQNT: 是 B* 0.3.17

日志/截图

chronocat.yml 配置

# yaml-language-server: $schema=https://chronocat.vercel.app/config-v0.schema.json
#
################################################################
#                      Chronocat 配置文件
################################################################
#
# 你好!
#
# 这是 Chronocat 的配置文件。Chronocat 的所有配置以及每个账号
# 的独立配置都存放在这个文件里。
#
# 这是 Chronocat 配置的文档:
# https://chronocat.vercel.app/config
# 如果还没有看过的话,请先看一下!
#
# 如果你现在并不是使用完整功能的编辑器编辑此文件的话,
# 我们推荐你使用一款完整功能的编辑器来编辑!
# 这样的编辑器在你不小心改错配置的时候会智能地给出提示。
# 想要了解更多请查看上面的文档 ↑
#
################################################################
#                           全局配置
################################################################
#
# 下面的配置是通用的!如果你只登录一个账号,
# 那么只需修改下面这部分配置即可!
#
################################################################

# servers:服务配置
#
# 配置 Chronocat 开启的服务。需要尤其注意服务列表的格式哦~
#
################################################################
#                           账号配置
################################################################
overrides:
  ##############################################################
  #
  # 下面的配置是每个账号专属的!修改下面的配置会覆盖上面的配置哦~
  # 修改的时候要特别注意:账号前空两格,账号内配置要空四格哦!
  #
  ##############################################################

  已替换为某个账号:
    servers:
      - type: red
        token: "与qq号一致"
        port: 16531

none bot 日志

2023-10-02 23:14:16 10-02 15:14:16 [SUCCESS] nonebot | RedProtocol 3356715156 | [message.private]: Message from 0: 查看 123456
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Checking for matchers in priority 1...
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Checking for matchers in priority 2...
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Checking for matchers in priority 5...
2023-10-02 23:14:16 10-02 15:14:16 [INFO] nonebot | Event will be handled by Matcher(type='message', module=src.plugins.tsdm, lineno=13)
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Running Matcher(type='message', module=src.plugins.tsdm, lineno=13)
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Running handler Dependent(call=handle_first_get)
2023-10-02 23:14:16 10-02 15:14:16 [DEBUG] nonebot | Running handler Dependent(call=handle_tid, parameterless=(Depends(Dependent(call=_key_getter)),))
2023-10-02 23:14:17 10-02 15:14:17 [INFO] tsdm | Get forum data successful.
2023-10-02 23:14:17 10-02 15:14:17 [INFO] tsdm | Get forum data successful.
2023-10-02 23:14:21 10-02 15:14:21 [INFO] tsdm | {'status': 0, 'id': '...', 'url': '/?...', 'deletetoken': '...', 'full_url': 'https://.../?...#...', 'passcode': '6f9UvqC3MRpkG3RxNtoekjTfrEoNwdotxJZBAAtsS9zr'}
2023-10-02 23:14:25 10-02 15:14:25 [INFO] tsdm | {'status': 0, 'id': '...', 'url': '/?...', 'deletetoken': '...', 'full_url': 'https://.../?...#...', 'passcode': 'GkGqC5UGpZea4tgRJghukJESt3zavza67Z1igSKh8a75'}
2023-10-02 23:14:25 10-02 15:14:25 [DEBUG] nonebot | RedProtocol | Calling API send_message
2023-10-02 23:14:25 10-02 15:14:25 [INFO] nonebot | Matcher(type='message', module=src.plugins.tsdm, lineno=13) running complete
2023-10-02 23:14:25 10-02 15:14:25 [ERROR] nonebot | Running Matcher(type='message', module=src.plugins.tsdm, lineno=13) failed.
2023-10-02 23:14:25 Traceback (most recent call last):
2023-10-02 23:14:25   File "/app/bot.py", line 39, in <module>
2023-10-02 23:14:25     nonebot.run(app="__mp_main__:app")
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/__init__.py", line 331, in run
2023-10-02 23:14:25     get_driver().run(*args, **kwargs)
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/drivers/none.py", line 70, in run
2023-10-02 23:14:25     loop.run_until_complete(self._serve())
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/asyncio/base_events.py", line 634, in run_until_complete
2023-10-02 23:14:25     self.run_forever()
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/asyncio/base_events.py", line 601, in run_forever
2023-10-02 23:14:25     self._run_once()
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1905, in _run_once
2023-10-02 23:14:25     handle._run()
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
2023-10-02 23:14:25     self._context.run(self._callback, *self._args)
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/message.py", line 476, in check_and_run_matcher
2023-10-02 23:14:25     await _run_matcher(
2023-10-02 23:14:25 > File "/usr/local/lib/python3.9/site-packages/nonebot/message.py", line 428, in _run_matcher
2023-10-02 23:14:25     await matcher.run(bot, event, state, stack, dependency_cache)
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 846, in run
2023-10-02 23:14:25     await self.simple_run(bot, event, state, stack, dependency_cache)
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 821, in simple_run
2023-10-02 23:14:25     await handler(
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/dependencies/__init__.py", line 113, in __call__
2023-10-02 23:14:25     return await cast(Callable[..., Awaitable[R]], self.call)(**values)
2023-10-02 23:14:25   File "/app/src/plugins/tsdm/__init__.py", line 91, in handle_tid
2023-10-02 23:14:25     await tsdm_get.send(f'解析: {link_html}\n源代码: {link_raw}')
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 554, in send
2023-10-02 23:14:25     return await bot.send(event=event, message=_message, **kwargs)
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/bot.py", line 223, in send
2023-10-02 23:14:25     resp = await self.call_api(
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/internal/adapter/bot.py", line 123, in call_api
2023-10-02 23:14:25     raise exception
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/internal/adapter/bot.py", line 98, in call_api
2023-10-02 23:14:25     result = await self.adapter._call_api(self, api, **data)
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/adapter.py", line 265, in _call_api
2023-10-02 23:14:25     return json.loads((await self.request(request)).content)  # type: ignore
2023-10-02 23:14:25   File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/adapter.py", line 271, in request
2023-10-02 23:14:25     raise NetworkError("Unauthorized!")
2023-10-02 23:14:25 nonebot.exception.NetworkError: NetworkError()
2023-10-02 23:14:25 10-02 15:14:25 [DEBUG] nonebot | Checking for matchers in priority 10...
2023-10-02 23:14:25 10-02 15:14:25 [DEBUG] nonebot | Checking for matchers completed

处理消息代码:

tsdm_get = on_command("tsdm_get", aliases={"查看"}, priority=5)
@tsdm_get.handle()
async def handle_first_get(matcher: Matcher, args: Message = CommandArg()):
    global status
    if not status:
        await tsdm_get.finish("未登录")
    else:
        tid = args.extract_plain_text()
        if tid:
            matcher.set_arg("tid", args)


@tsdm_get.got("tid", prompt="请输入帖子ID")
async def handle_tid(tid: Message = Arg(), tid_id=ArgPlainText("tid")):
    # account.purchase(tid_id)
    forum_data = account.get_forum_data(tid_id)
    if forum_data:
        link_raw = utils.pastebin_send(forum_data, False)
        link_html = utils.pastebin_send(forum_data, True)
        await tsdm_get.send(f'解析: {link_html}\n源代码: {link_raw}')
    else:
        await tsdm_get.finish("获取失败")

.env 配置

RED_BOTS='
[
  {
    "port": "16531",
    "token": "与qq号一致",
    "host": "host.docker.internal"
  }
]
'
DRIVER=~httpx+~websockets
@SofiaXu SofiaXu added the bug Something isn't working label Oct 2, 2023
@RF-Tar-Railt
Copy link
Member

你能试试手动请求api吗

@SofiaXu
Copy link
Author

SofiaXu commented Oct 3, 2023

你能试试手动请求api吗

从网页端 ws 客户端连接,发送消息后 qqnt 直接闪退了,我或许需要去给 BetterQQNT 提 issue?

发送消息 09:23:35
{ "type": "meta::connect", "payload": { "token": "..." } }
收到消息 09:23:35
{"type":"meta::connect","payload":{"version":"0.0.48","name":"chronocat","authData":{"account":"...","mainAccount":"","uin":"...","uid":"...","nickName":"","gender":0,"age":0,"faceUrl":"","a2":"","d2":"","d2key":""}}}
发送消息 09:23:43
{ "type": "message::send", "payload": { "peer": { "chatType": 1, "peerUin": "..." }, "elements": [ { "elementType": 1, "textElement": { "content": "1" } } ] } }

@zhaomaoniu
Copy link
Member

你的 QQNT 版本是否是9.9.3?Chronocat暂不支持此版本

@SofiaXu
Copy link
Author

SofiaXu commented Oct 3, 2023

你的 QQNT 版本是否是9.9.3?Chronocat暂不支持此版本

是的,版本是 9.9.3-17153,我这边看 BetterQQNT 那边支持这个版本升级的,我降级一下,感谢

@SofiaXu SofiaXu closed this as completed Oct 3, 2023
@SofiaXu SofiaXu reopened this Oct 7, 2023
@SofiaXu
Copy link
Author

SofiaXu commented Oct 7, 2023

我升级了一下新版,并看了源代码和chronocat里的文档,好像send_message这个api在最新版里换成了upload才会有这个报错,大佬最近有计划更新吗

@RF-Tar-Railt
Copy link
Member

我升级了一下新版,并看了源代码和chronocat里的文档,好像send_message这个api在最新版里换成了upload才会有这个报错,大佬最近有计划更新吗

你换回50以下的chronocat再看看

@SofiaXu
Copy link
Author

SofiaXu commented Oct 7, 2023

我升级了一下新版,并看了源代码和chronocat里的文档,好像send_message这个api在最新版里换成了upload才会有这个报错,大佬最近有计划更新吗

你换回50以下的chronocat再看看

现在是49

@SofiaXu
Copy link
Author

SofiaXu commented Oct 7, 2023

我升级了一下新版,并看了源代码和chronocat里的文档,好像send_message这个api在最新版里换成了upload才会有这个报错,大佬最近有计划更新吗

你换回50以下的chronocat再看看

试了一下,0.47也是这个报错

10-07 05:36:10 [INFO] nonebot | RedProtocol | Bot [隐私信息] connected, Chronocat Version: 0.0.47
10-07 05:36:28 [SUCCESS] nonebot | RedProtocol [隐私信息] | [message.private]: Message from 0: 嫖 [隐私信息]
10-07 05:36:28 [DEBUG] nonebot | Checking for matchers in priority 1...
10-07 05:36:28 [DEBUG] nonebot | Checking for matchers in priority 2...
10-07 05:36:28 [DEBUG] nonebot | Checking for matchers in priority 5...
10-07 05:36:28 [INFO] nonebot | Event will be handled by Matcher(type='message', module=src.plugins.tsdm, lineno=13)
10-07 05:36:28 [DEBUG] nonebot | Running Matcher(type='message', module=src.plugins.tsdm, lineno=13)
10-07 05:36:28 [DEBUG] nonebot | Running handler Dependent(call=handle_first_get)
10-07 05:36:28 [DEBUG] nonebot | Running handler Dependent(call=handle_tid, parameterless=(Depends(Dependent(call=_key_getter)),))
10-07 05:36:29 [INFO] tsdm | Get forum data successful.
10-07 05:36:33 [INFO] tsdm | [隐私信息]
10-07 05:36:37 [INFO] tsdm | [隐私信息]
10-07 05:36:37 [DEBUG] nonebot | RedProtocol | Calling API send_message
10-07 05:36:37 [INFO] nonebot | Matcher(type='message', module=src.plugins.tsdm, lineno=13) running complete
10-07 05:36:37 [ERROR] nonebot | Running Matcher(type='message', module=src.plugins.tsdm, lineno=13) failed.
Traceback (most recent call last):
  File "/app/bot.py", line 39, in <module>
    nonebot.run(app="__mp_main__:app")
  File "/usr/local/lib/python3.9/site-packages/nonebot/__init__.py", line 331, in run
    get_driver().run(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/nonebot/drivers/none.py", line 70, in run
    loop.run_until_complete(self._serve())
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 634, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 601, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1905, in _run_once
    handle._run()
  File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.9/site-packages/nonebot/message.py", line 476, in check_and_run_matcher
    await _run_matcher(
> File "/usr/local/lib/python3.9/site-packages/nonebot/message.py", line 428, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 846, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 821, in simple_run
    await handler(
  File "/usr/local/lib/python3.9/site-packages/nonebot/dependencies/__init__.py", line 113, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "/app/src/plugins/tsdm/__init__.py", line 91, in handle_tid
    await tsdm_get.send(f'解析: {link_html}\n源代码: {link_raw}')
  File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 554, in send
    return await bot.send(event=event, message=_message, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/bot.py", line 223, in send
    resp = await self.call_api(
  File "/usr/local/lib/python3.9/site-packages/nonebot/internal/adapter/bot.py", line 123, in call_api
    raise exception
  File "/usr/local/lib/python3.9/site-packages/nonebot/internal/adapter/bot.py", line 98, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/adapter.py", line 265, in _call_api
    return json.loads((await self.request(request)).content)  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/adapter.py", line 271, in request
    raise NetworkError("Unauthorized!")
nonebot.exception.NetworkError: NetworkError()
10-07 05:36:37 [DEBUG] nonebot | Checking for matchers in priority 10...
10-07 05:36:37 [DEBUG] nonebot | Checking for matchers completed

@RF-Tar-Railt
Copy link
Member

File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/adapter.py", line 271, in request

你去这里,把请求的返回值打印一下

@SofiaXu
Copy link
Author

SofiaXu commented Oct 7, 2023

File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/adapter.py", line 271, in request

你去这里,把请求的返回值打印一下

日志

10-07 06:44:25 [ERROR] nonebot | RedProtocol | Error while calling API http://host.docker.internal:16531/api/message/send 502
10-07 06:44:25 [ERROR] nonebot | RedProtocol | Error while calling API http://host.docker.internal:16531/api/message/send <CIMultiDict('connection': 'close', 'content-length': '0')>
10-07 06:44:25 [ERROR] nonebot | RedProtocol | Error while calling API http://host.docker.internal:16531/api/message/send b''

代码

            log("ERROR", f"Error while calling API <y>{setup.url}</y> {resp.status_code}")
            log("ERROR", f"Error while calling API <y>{setup.url}</y> {resp.headers}")
            log("ERROR", f"Error while calling API <y>{setup.url}</y> {resp.content}")

@RF-Tar-Railt
Copy link
Member

更新0.0.51再看看

@SofiaXu
Copy link
Author

SofiaXu commented Oct 11, 2023

更新0.0.51再看看

10-11 10:32:17 [ERROR] nonebot | Running Matcher(type='message', module=src.plugins.tsdm, lineno=13) failed.
Traceback (most recent call last):
  File "/app/bot.py", line 39, in <module>
    nonebot.run(app="__mp_main__:app")
  File "/usr/local/lib/python3.9/site-packages/nonebot/__init__.py", line 331, in run
    get_driver().run(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/nonebot/drivers/none.py", line 70, in run
    loop.run_until_complete(self._serve())
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 634, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 601, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1905, in _run_once
    handle._run()
  File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.9/site-packages/nonebot/message.py", line 476, in check_and_run_matcher
    await _run_matcher(
> File "/usr/local/lib/python3.9/site-packages/nonebot/message.py", line 428, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 846, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 821, in simple_run
    await handler(
  File "/usr/local/lib/python3.9/site-packages/nonebot/dependencies/__init__.py", line 113, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "/app/src/plugins/tsdm/__init__.py", line 91, in handle_tid
    await tsdm_get.send(f'解析: {link_html}\n源代码: {link_raw}')
  File "/usr/local/lib/python3.9/site-packages/nonebot/internal/matcher/matcher.py", line 554, in send
    return await bot.send(event=event, message=_message, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/bot.py", line 223, in send
    resp = await self.call_api(
  File "/usr/local/lib/python3.9/site-packages/nonebot/internal/adapter/bot.py", line 123, in call_api
    raise exception
  File "/usr/local/lib/python3.9/site-packages/nonebot/internal/adapter/bot.py", line 98, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/adapter.py", line 241, in _call_api
    return json.loads((await self.request(request)).content)  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/nonebot/adapters/red/adapter.py", line 250, in request
    raise ActionFailed(
nonebot.exception.ActionFailed: ActionFailed("HTTP status code 502 response body: b''")

@RF-Tar-Railt RF-Tar-Railt changed the title [Bug] 发送消息时提示 Unauthorized [Bug] 发送消息时提示 502 Oct 11, 2023
@ilharp
Copy link

ilharp commented Oct 12, 2023

你尝试发送的消息中有图片吗或者其他媒体内容吗?

如果有的话,方便把图片打个压缩包发出来吗?

@SofiaXu
Copy link
Author

SofiaXu commented Oct 18, 2023

你尝试发送的消息中有图片吗或者其他媒体内容吗?

如果有的话,方便把图片打个压缩包发出来吗?

没有,只有文字,log文件已经很清楚的显示发的啥了

@RF-Tar-Railt
Copy link
Member

chronocat已重新public:
https://github.com/chrononeko/chronocat
cc v0.2版本后不再支持red协议
若仍然使用red协议请使用cc v0.1版本
使用v0.2以上的cc清更换适配器为satori:https://github.com/nonebot/adapter-satori

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants