nonebot / adapter-feishu

NoneBot2 飞书适配器 / FeiShu (LarkSuite) adapter for nonebot2
https://feishu.adapters.nonebot.dev
MIT License
30 stars 7 forks source link

Question: 配置适配器多 Bot 实例时出现错误 #77

Closed Tyler-ytr closed 1 year ago

Tyler-ytr commented 1 year ago

描述问题:

已有企业自建应用A,对接了机器人a;现在ctrl+c bot.py然后修改.env尝试把机器人a对接另一个账号的企业自建应用应用B,产生了如下问题:

09-19 17:47:51 [ERROR] uvicorn | Traceback (most recent call last):
  File "/home/tyleryin/feishu_bot/bagu_bot/.venv/lib/python3.8/site-packages/starlette/routing.py", line 677, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "/usr/lib/python3.8/contextlib.py", line 171, in __aenter__
    return await self.gen.__anext__()
  File "/home/tyleryin/feishu_bot/bagu_bot/.venv/lib/python3.8/site-packages/nonebot/drivers/fastapi.py", line 168, in _lifespan_manager
    await self._lifespan.startup()
  File "/home/tyleryin/feishu_bot/bagu_bot/.venv/lib/python3.8/site-packages/nonebot/drivers/_lifespan.py", line 36, in startup
    await self._run_lifespan_func(self._startup_funcs)
  File "/home/tyleryin/feishu_bot/bagu_bot/.venv/lib/python3.8/site-packages/nonebot/drivers/_lifespan.py", line 30, in _run_lifespan_func
    await cast(ASYNC_LIFESPAN_FUNC, func)()
  File "/home/tyleryin/feishu_bot/bagu_bot/.venv/lib/python3.8/site-packages/nonebot/adapters/feishu/adapter.py", line 87, in _
    bot_info = parse_obj_as(BotInfo, result.get("bot", {}))
  File "pydantic/tools.py", line 38, in pydantic.tools.parse_obj_as
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 5 validation errors for ParsingModel[BotInfo]
__root__ -> activate_status
  field required (type=value_error.missing)
__root__ -> app_name
  field required (type=value_error.missing)
__root__ -> avatar_url
  field required (type=value_error.missing)
__root__ -> ip_white_list
  field required (type=value_error.missing)
__root__ -> open_id
  field required (type=value_error.missing)

09-19 17:47:51 [ERROR] uvicorn | Application startup failed. Exiting.

于此同时,修改.env回A的配置又可以正常启动

StarHeartHunt commented 1 year ago

如果用凭证手动请求一下 bot/v3/info 返回的是什么,应该是 B 没有开启机器人权限或者未启用。

Tyler-ytr commented 1 year ago

请问这里有请求的命令吗?

Tyler-ytr commented 1 year ago

另外,在飞书开放平台把原有的请求地址配置部分删除,过一段时间之后启动python bot.py 也会出现一样的问题;(此时飞书开放平台请求地址配置也没法成功,显示json不合法

StarHeartHunt commented 1 year ago

请问这里有请求的命令吗?

可以直接修改 /home/tyleryin/feishu_bot/bagu_bot/.venv/lib/python3.8/site-packages/nonebot/adapters/feishu/adapter.py 87 行前后 print 一下 result

另外,在飞书开放平台把原有的请求地址配置部分删除,过一段时间之后启动python bot.py 也会出现一样的问题;(此时飞书开放平台请求地址配置也没法成功,显示json不合法

我这里没有复现,可以像上面说的一样看一下飞书返回了什么

Tyler-ytr commented 1 year ago

09-19 20:41:55 [INFO] uvicorn | Waiting for application startup. {'code': 11205, 'msg': 'app do not have bot'}

StarHeartHunt commented 1 year ago

09-19 20:41:55 [INFO] uvicorn | Waiting for application startup. {'code': 11205, 'msg': 'app do not have bot'}

没有开启机器人能力,按照飞书文档开启机器人能力后发布

需要启用机器人能力(前往开发者后台 - 选择你要获取信息的应用 - 导航栏点击应用功能 - 机器人,开启机器人能力并发布后即可。)