SAGIRI-kawaii / sagiri-bot

基于Graia Ariadne和Mirai的QQ机器人 SAGIRI-BOT
GNU Affero General Public License v3.0
695 stars 83 forks source link

[Bug Report] 无法启动机器人/生成alembic.ini #401

Closed narwhrl closed 1 year ago

narwhrl commented 1 year ago

问题

在进行到配置 alembic这一步骤时,使用python3 main.py命令启动机器人时出现报错, 无法启动机器人,也无法生成alembic.ini mcl可以正常启动并使用

如何复现

1.使用环境 Ubuntu 22.04,Python 3.10.6 2.不使用Anaconda/Miniconda,不使用虚拟环境,使用poetry 3.运行了python3 main.py 4.报错提示name 'Repo' is not defined. 详见具体错误日志

预期行为

No response

使用环境

日志/截图

2023-02-11 12:28:51.902 | ERROR    | shared.utils.self_upgrade:<module>:16 - 未检测到git!
Traceback (most recent call last):
  File "/root/sagiri-bot/main.py", line 31, in <module>
    from core import Sagiri
  File "/root/sagiri-bot/core/__init__.py", line 47, in <module>
    from shared.utils.self_upgrade import UpdaterService
  File "/root/sagiri-bot/shared/utils/self_upgrade.py", line 23, in <module>
    def get_current_repo() -> Repo | None:
NameError: name 'Repo' is not defined. Did you mean: 'repr'?
SAGIRI-kawaii commented 1 year ago

是否安装git并能正常使用,是否使用git clone下载项目?

narwhrl commented 1 year ago

是否安装git并能正常使用,是否使用git clone下载项目?

是可以的,bot文件就是我用git clone下载下来的

root@racknerd-72214b:~/test# git clone https://github.com/SAGIRI-kawaii/sagiri-bot.git
Cloning into 'sagiri-bot'...
remote: Enumerating objects: 9134, done.
remote: Counting objects: 100% (1155/1155), done.
remote: Compressing objects: 100% (548/548), done.
remote: Total 9134 (delta 572), reused 1076 (delta 551), pack-reused 7979
Receiving objects: 100% (9134/9134), 222.51 MiB | 17.50 MiB/s, done.
Resolving deltas: 100% (5088/5088), done.
Updating files: 100% (414/414), done.

服务器在美国,应该不会存在网络问题

nullqwertyuiop commented 1 year ago

尝试使用 poetry run python main.py 运行?

narwhrl commented 1 year ago

尝试使用 poetry run python main.py 运行?

确实成功启动机器人了!但是紧接着就出现了新的报错... 想到文档里提到第一次启动机器人会退出,于是我就去检查生成的alembic.ini文件, 但里面sqlalchemy.url的预设值(第一次进入文件)就是sqlalchemy.url = sqlite:///data.db,我为了确认还再粘贴了一次。 重新用刚才的命令启动机器人,还是出现了和刚刚第一次启动时一样的报错 详细日志如下:

2023-02-11 12:57:15.440 | INFO     | launart.manager:_launchable_task_done_callback:53 - Component sagiri.core.alembic completed preparation.
2023-02-11 12:57:15.441 | INFO     | launart.manager:_launchable_task_done_callback:68 - [sagiri.core.alembic] completed.
2023-02-11 12:57:15.919 | ERROR    | launart.manager:_launchable_task_done_callback:43 - [web.render/playwright] raised a exception.
Traceback (most recent call last):

> File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/graiax/playwright/service.py", line 177, in launch
    self.browser = await browser_type.launch(**self.launch_config)
    │    │               │            │        │    └ {'proxy': None}
    │    │               │            │        └ <graiax.playwright.service.PlaywrightService object at 0x7f541d5afa90>
    │    │               │            └ <function BrowserType.launch at 0x7f541c6257e0>
    │    │               └ <BrowserType name=chromium executable_path=/root/.cache/ms-playwright/chromium-1045/chrome-linux/chrome>
    │    └ None
    └ <graiax.playwright.service.PlaywrightService object at 0x7f541d5afa90>
  File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/playwright/async_api/_generated.py", line 14340, in launch
    await self._impl_obj.launch(
          │    │         └ <function BrowserType.launch at 0x7f541c5e0160>
          │    └ <BrowserType name=chromium executable_path=/root/.cache/ms-playwright/chromium-1045/chrome-linux/chrome>
          └ <BrowserType name=chromium executable_path=/root/.cache/ms-playwright/chromium-1045/chrome-linux/chrome>
  File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/playwright/_impl/_browser_type.py", line 93, in launch
    Browser, from_channel(await self._channel.send("launch", params))
    │        │                  │    │        │              └ {}
    │        │                  │    │        └ <function Channel.send at 0x7f541c72c430>
    │        │                  │    └ <playwright._impl._connection.Channel object at 0x7f540ef8e9b0>
    │        │                  └ <BrowserType name=chromium executable_path=/root/.cache/ms-playwright/chromium-1045/chrome-linux/chrome>
    │        └ <function from_channel at 0x7f541c69dbd0>
    └ <class 'playwright._impl._browser.Browser'>
  File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 44, in send
    return await self._connection.wrap_api_call(
                 │    │           └ <function Connection.wrap_api_call at 0x7f541c72dc60>
                 │    └ <playwright._impl._connection.Connection object at 0x7f540eafce80>
                 └ <playwright._impl._connection.Channel object at 0x7f540ef8e9b0>
  File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 419, in wrap_api_call
    return await cb()
                 └ <function Channel.send.<locals>.<lambda> at 0x7f540e256950>
  File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 79, in inner_send
    result = next(iter(done)).result()
                       └ {<Future finished exception=Error('\n╔══════════════════════════════════════════════════════╗\n║ Host system is missing depen...

playwright._impl._api_types.Error: 
╔══════════════════════════════════════════════════════╗
║ Host system is missing dependencies to run browsers. ║
║ Please install them with the following command:      ║
║                                                      ║
║     playwright install-deps                          ║
║                                                      ║
║ Alternatively, use apt:                              ║
║     apt-get install libgbm1\                         ║
║         libxkbcommon0                                ║
║                                                      ║
║ <3 Playwright Team                                   ║
╚══════════════════════════════════════════════════════╝
2023-02-11 12:57:15.928 | CRITICAL | launart.manager:launch:374 - Layer #1:[web.render/playwright] failed during preparation. Aborting.
2023-02-11 12:57:15.930 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [elizabeth.connection.3229135621.websocket_client_connection] was cancelled in abort.
2023-02-11 12:57:15.931 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [http.asgi_runner/uvicorn] was cancelled in abort.
2023-02-11 12:57:15.931 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [scheduler.service] was cancelled in abort.
2023-02-11 12:57:15.931 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [http.client/aiohttp] was cancelled in abort.
2023-02-11 12:57:15.932 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [elizabeth.service] was cancelled in abort.
2023-02-11 12:57:15.932 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [cache.client/memcache] was cancelled in abort.
2023-02-11 12:57:15.933 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [elizabeth.connection.3229135621.http_client_connection] was cancelled in abort.
2023-02-11 12:57:15.935 | SUCCESS  | launart.manager:launch_blocking:507 - asyncio shutdown complete.
nullqwertyuiop commented 1 year ago

尝试使用 poetry run python main.py 运行?

确实成功启动机器人了!但是紧接着就出现了新的报错... 想到文档里提到第一次启动机器人会退出,于是我就去检查生成的alembic.ini文件, 但里面sqlalchemy.url的预设值(第一次进入文件)就是sqlalchemy.url = sqlite:///data.db,我为了确认还再粘贴了一次。 重新用刚才的命令启动机器人,还是出现了和刚刚第一次启动时一样的报错 详细日志如下:

2023-02-11 12:57:15.440 | INFO     | launart.manager:_launchable_task_done_callback:53 - Component sagiri.core.alembic completed preparation.
2023-02-11 12:57:15.441 | INFO     | launart.manager:_launchable_task_done_callback:68 - [sagiri.core.alembic] completed.
2023-02-11 12:57:15.919 | ERROR    | launart.manager:_launchable_task_done_callback:43 - [web.render/playwright] raised a exception.
Traceback (most recent call last):

> File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/graiax/playwright/service.py", line 177, in launch
    self.browser = await browser_type.launch(**self.launch_config)
    │    │               │            │        │    └ {'proxy': None}
    │    │               │            │        └ <graiax.playwright.service.PlaywrightService object at 0x7f541d5afa90>
    │    │               │            └ <function BrowserType.launch at 0x7f541c6257e0>
    │    │               └ <BrowserType name=chromium executable_path=/root/.cache/ms-playwright/chromium-1045/chrome-linux/chrome>
    │    └ None
    └ <graiax.playwright.service.PlaywrightService object at 0x7f541d5afa90>
  File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/playwright/async_api/_generated.py", line 14340, in launch
    await self._impl_obj.launch(
          │    │         └ <function BrowserType.launch at 0x7f541c5e0160>
          │    └ <BrowserType name=chromium executable_path=/root/.cache/ms-playwright/chromium-1045/chrome-linux/chrome>
          └ <BrowserType name=chromium executable_path=/root/.cache/ms-playwright/chromium-1045/chrome-linux/chrome>
  File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/playwright/_impl/_browser_type.py", line 93, in launch
    Browser, from_channel(await self._channel.send("launch", params))
    │        │                  │    │        │              └ {}
    │        │                  │    │        └ <function Channel.send at 0x7f541c72c430>
    │        │                  │    └ <playwright._impl._connection.Channel object at 0x7f540ef8e9b0>
    │        │                  └ <BrowserType name=chromium executable_path=/root/.cache/ms-playwright/chromium-1045/chrome-linux/chrome>
    │        └ <function from_channel at 0x7f541c69dbd0>
    └ <class 'playwright._impl._browser.Browser'>
  File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 44, in send
    return await self._connection.wrap_api_call(
                 │    │           └ <function Connection.wrap_api_call at 0x7f541c72dc60>
                 │    └ <playwright._impl._connection.Connection object at 0x7f540eafce80>
                 └ <playwright._impl._connection.Channel object at 0x7f540ef8e9b0>
  File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 419, in wrap_api_call
    return await cb()
                 └ <function Channel.send.<locals>.<lambda> at 0x7f540e256950>
  File "/root/.cache/pypoetry/virtualenvs/sagiri-bot-J48-ZoL2-py3.10/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 79, in inner_send
    result = next(iter(done)).result()
                       └ {<Future finished exception=Error('\n╔══════════════════════════════════════════════════════╗\n║ Host system is missing depen...

playwright._impl._api_types.Error: 
╔══════════════════════════════════════════════════════╗
║ Host system is missing dependencies to run browsers. ║
║ Please install them with the following command:      ║
║                                                      ║
║     playwright install-deps                          ║
║                                                      ║
║ Alternatively, use apt:                              ║
║     apt-get install libgbm1\                         ║
║         libxkbcommon0                                ║
║                                                      ║
║ <3 Playwright Team                                   ║
╚══════════════════════════════════════════════════════╝
2023-02-11 12:57:15.928 | CRITICAL | launart.manager:launch:374 - Layer #1:[web.render/playwright] failed during preparation. Aborting.
2023-02-11 12:57:15.930 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [elizabeth.connection.3229135621.websocket_client_connection] was cancelled in abort.
2023-02-11 12:57:15.931 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [http.asgi_runner/uvicorn] was cancelled in abort.
2023-02-11 12:57:15.931 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [scheduler.service] was cancelled in abort.
2023-02-11 12:57:15.931 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [http.client/aiohttp] was cancelled in abort.
2023-02-11 12:57:15.932 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [elizabeth.service] was cancelled in abort.
2023-02-11 12:57:15.932 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [cache.client/memcache] was cancelled in abort.
2023-02-11 12:57:15.933 | WARNING  | launart.manager:_launchable_task_done_callback:37 - [elizabeth.connection.3229135621.http_client_connection] was cancelled in abort.
2023-02-11 12:57:15.935 | SUCCESS  | launart.manager:launch_blocking:507 - asyncio shutdown complete.

Playwright 缺少依赖,请运行 apt-get install libgbm1 libxkbcommon0poetry run playwright install-deps

narwhrl commented 1 year ago

Playwright 缺少依赖,请运行 apt-get install libgbm1 libxkbcommon0poetry run playwright install-deps

非常感谢!!机器人终于可以正常启动了,但是不知道为什么websocket始终无法连接上,我的mcl已经正常启动运行,也可以接收到QQ消息,配置的Verify_key也是一致的,配置文件如下:

mirai-api-http的配置文件setting.yml如下:

adapters:
  - http
  - ws
debug: false
enableVerify: true
verifyKey: 01081664 # 你可以自己设定, 这里作为示范, 请保持和 config.yaml 中 verify_key 项一致
singleMode: false
cacheSize: 4096 # 可选, 缓存大小, 默认4096. 缓存过小会导致引用回复与撤回消息失败
adapterSettings:
  ## 详情看 http adapter 使用说明 配置
  http:
    host: localhost
    port: 23456 # 端口
    cors: [*]

  ## 详情看 websocket adapter 使用说明 配置
  ws:
    host: localhost
    port: 23456 # 端口
    reservedSyncId: -1 # 确保为 -1, 否则 WebsocketAdapter(Experimental) 没法正常工作.

sagiri-bot的配置文件config.yaml如下:

mirai_host: http://localhost:23456
verify_key: !!str 01081664
db_link: sqlite+aiosqlite:///data.db
api_port: 54321
api_expose: false
web_manager_api: true
web_manager_auto_boot: true
proxy: proxy
auto_upgrade: false

实测去掉sagiri-bot配置文件config.yamlverify_key中的!!str也出现上述报错QAQ

会不会是http和ws冲突了?

sagiri-bot的报错日志:

2023-02-11 13:11:30.265 | WARNING  | graia.ariadne.connection.ws:_:77 - Websocket reconnecting...
2023-02-11 13:11:30.272 | WARNING  | graia.amnesia.builtins.aiohttp:connection_manage:229 - ClientConnectorError(ConnectionKey(host='localhost', port=23456, is_ssl=False, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None), ConnectionRefusedError(111, "Connect call failed ('::1', 23456, 0, 0)"))
2023-02-11 13:11:30.273 | WARNING  | graia.ariadne.connection.ws:_:75 - Websocket reconnecting in 5s...
nullqwertyuiop commented 1 year ago

Playwright 缺少依赖,请运行 apt-get install libgbm1 libxkbcommon0poetry run playwright install-deps

非常感谢!!机器人终于可以正常启动了,但是不知道为什么websocket始终无法连接上,我的mcl已经正常启动运行,也可以接收到QQ消息,配置的Verify_key也是一致的,配置文件如下:

mirai-api-http的配置文件setting.yml如下:

adapters:
  - http
  - ws
debug: false
enableVerify: true
verifyKey: 01081664 # 你可以自己设定, 这里作为示范, 请保持和 config.yaml 中 verify_key 项一致
singleMode: false
cacheSize: 4096 # 可选, 缓存大小, 默认4096. 缓存过小会导致引用回复与撤回消息失败
adapterSettings:
  ## 详情看 http adapter 使用说明 配置
  http:
    host: localhost
    port: 23456 # 端口
    cors: [*]

  ## 详情看 websocket adapter 使用说明 配置
  ws:
    host: localhost
    port: 23456 # 端口
    reservedSyncId: -1 # 确保为 -1, 否则 WebsocketAdapter(Experimental) 没法正常工作.

sagiri-bot的配置文件config.yaml如下:

mirai_host: http://localhost:23456
verify_key: !!str 01081664
db_link: sqlite+aiosqlite:///data.db
api_port: 54321
api_expose: false
web_manager_api: true
web_manager_auto_boot: true
proxy: proxy
auto_upgrade: false

实测去掉sagiri-bot配置文件config.yamlverify_key中的!!str也出现上述报错QAQ

会不会是http和ws冲突了?

sagiri-bot的报错日志:

2023-02-11 13:11:30.265 | WARNING  | graia.ariadne.connection.ws:_:77 - Websocket reconnecting...
2023-02-11 13:11:30.272 | WARNING  | graia.amnesia.builtins.aiohttp:connection_manage:229 - ClientConnectorError(ConnectionKey(host='localhost', port=23456, is_ssl=False, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None), ConnectionRefusedError(111, "Connect call failed ('::1', 23456, 0, 0)"))
2023-02-11 13:11:30.273 | WARNING  | graia.ariadne.connection.ws:_:75 - Websocket reconnecting in 5s...

请阅读部署文档中 FAQ 部分,谢谢。

narwhrl commented 1 year ago

请阅读部署文档中 FAQ 部分,谢谢。

这些方法我都试了一下,更换端口,更换verify_key,重启vps以清除其他可能存在的mcl服务,mcl也完全正常启动并登录了,还能看到往这个机器人发的消息,说明登录这方面也没问题 最后还是出现了一样的报错... 我的报错和FAQ里的报错还是有不一样的TAT

narwhrl commented 1 year ago

请阅读部署文档中 FAQ 部分,谢谢。

我用docker方式部署也是一样的报错TAT... 只是ip变成了sagiri-mah的容器ip

SAGIRI-kawaii commented 1 year ago

现在还有问题吗