adapter-red icon indicating copy to clipboard operation
adapter-red copied to clipboard

[Bug] 发送消息时提示 502

Open SofiaXu opened this issue 1 year ago • 15 comments

请确认:

  • [x] 问题的标题明确
  • [x] 我翻阅过其他的 issue 并且找不到类似的问题
  • [x] 我已经阅读了相关文档 并仍然认为这是一个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 avatar Oct 02 '23 15:10 SofiaXu