RockChinQ / QChatGPT

😎高稳定性、🧩支持扩展、🦄多模态的 ChatGPT QQ / QQ频道 / One Bot 机器人🤖 | 支持 OpenAI GPT、Claude、Gemini Pro、DeepSeek、Moonshot(Kimi)、gpt4free、One API、Ollama 的 QQ / QQ频道 / OneBot 机器人 / Agent 平台
https://q.rkcn.top
GNU Affero General Public License v3.0
4.34k stars 332 forks source link

运行main.py报错 #10

Closed Cris-Young closed 1 year ago

Cris-Young commented 1 year ago

Python版本:3.11.1 Mirai:2.6.2,默认配置部署,账号已经成功登陆,能正常监听到消息 操作方式:按照文档操作,运行到最后一步报错

报错内容:

D:\Project\QQRobot\QChatGPT\QChatGPT>python main.py
[2022-12-10 12:19:18.026] main.py (69) - [INFO] : 程序启动完成
2022-12-10 12:19:18 - WARNING  未找到可用的 ASGI 服务,反向 WebSocket 和 WebHook 上报将不可用。
仅 HTTP 轮询与正向 WebSocket 可用。
建议安装 ASGI 服务器,如 uvicorn或 hypercorn。
在命令行键入:
    pip install uvicorn
或者
    pip install hypercorn
[2022-12-10 12:19:18.026] bot.py (260) - [WARNING] : 未找到可用的 ASGI 服务,反向 WebSocket 和 WebHook 上报将不可用。
仅 HTTP 轮询与正向 WebSocket 可用。
建议安装 ASGI 服务器,如 `uvicorn` 或 `hypercorn`。
在命令行键入:
    pip install uvicorn
或者
    pip install hypercorn
2022-12-10 12:19:28 - ERROR
[2022-12-10 12:19:28.028] base.py (43) - [ERROR] :
Exception in thread Thread-2 (run):
Traceback (most recent call last):
  File "D:\Code\Python\Lib\site-packages\websockets\legacy\client.py", line 666, in __await_impl__
    await protocol.handshake(
  File "D:\Code\Python\Lib\site-packages\websockets\legacy\client.py", line 332, in handshake
    raise InvalidStatusCode(status_code, response_headers)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 404

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Code\Python\Lib\asyncio\tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "D:\Code\Python\Lib\site-packages\websockets\legacy\client.py", line 680, in __await_impl__
    await protocol.wait_closed()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Code\Python\Lib\threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "D:\Code\Python\Lib\threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "D:\Code\Python\Lib\site-packages\mirai\bot.py", line 197, in run
    MiraiRunner(self).run(host, port, asgi_server, **kwargs)
  File "D:\Code\Python\Lib\site-packages\mirai\bot.py", line 274, in run
    asyncio.run(self._run())
  File "D:\Code\Python\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "D:\Code\Python\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Code\Python\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "D:\Code\Python\Lib\site-packages\mirai\bot.py", line 238, in _run
    await self.startup()
  File "D:\Code\Python\Lib\site-packages\mirai\bot.py", line 226, in startup
    await asyncio.gather(*coros)
  File "D:\Code\Python\Lib\site-packages\mirai\bot.py", line 135, in startup
    await self._adapter.login(self.qq)
  File "D:\Code\Python\Lib\site-packages\mirai\adapters\base.py", line 35, in wrapped
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Code\Python\Lib\site-packages\mirai\adapters\websocket.py", line 187, in login
    self.connection = await connect(self.host_name, extra_headers=headers)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Code\Python\Lib\site-packages\websockets\legacy\client.py", line 659, in __await_impl_timeout__
    return await asyncio.wait_for(self.__await_impl__(), self.open_timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Code\Python\Lib\asyncio\tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc`

根据提示安装了uvicorn,然后报错:

`D:\Project\QQRobot\QChatGPT\QChatGPT>python main.py
[2022-12-10 12:19:58.582] main.py (69) - [INFO] : 程序启动完成
Exception in thread Thread-2 (run):
Traceback (most recent call last):
  File "D:\Code\Python\Lib\threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "D:\Code\Python\Lib\threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "D:\Code\Python\Lib\site-packages\mirai\bot.py", line 197, in run
    MiraiRunner(self).run(host, port, asgi_server, **kwargs)
  File "D:\Code\Python\Lib\site-packages\mirai\bot.py", line 255, in run
    if not asgi_serve(
           ^^^^^^^^^^^
  File "D:\Code\Python\Lib\site-packages\mirai\asgi.py", line 206, in asgi_serve
    run(app, host=host, port=port, debug=True, **kwargs)
TypeError: run() got an unexpected keyword argument 'debug'`
RockChinQ commented 1 year ago

【不正确】mirai-api-http的配置没有配置成ws方式,参考https://yiri-mirai.wybxc.cc/tutorials/01/configuration#3-%E9%85%8D%E7%BD%AE-mirai-api-http

【错误原因】 错误地安装了uvicorn或hypercorn

2575169674 commented 1 year ago

如果你配置成ws之后还存在这种问题应该是你安装了uvicorn或者hypercorn,卸载掉就行了 ps: 卸载命令 pip3 uninstall uvicorn pip3 uninstall hypercorn