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

最近一直出现<NetWorkError message=HTTP request failed> #24

Open
TheLZY opened this issue Apr 4, 2023 · 10 comments
Open

最近一直出现<NetWorkError message=HTTP request failed> #24

TheLZY opened this issue Apr 4, 2023 · 10 comments
Assignees

Comments

@TheLZY
Copy link

TheLZY commented Apr 4, 2023

最近经常出现 networkerror
偶尔能收一会儿消息,但是都会在五分钟之内开始报错

新装了好几次,回退版本到 v0.1.0b8 还是有这个问题

感觉是处理上一个生命周期时碰到的问题解决不了?因为一旦报错,重启后也会一直报错。

但是我去bot.py 里注释掉 nonebot.load_plugins("plugins") 之后,重启一下,就不会有问题了

配置文件:
.env.prod

DRIVER=~fastapi+~httpx
telegram_bots = [{"token": "..."}]
NICKNAME=["lzy","thelzybot"] # 机器人的昵称
FASTAPI_RELOAD=false

bot.py

import nonebot
from nonebot.adapters.telegram import Adapter as TelegramAdapter

nonebot.init()
app = nonebot.get_asgi()

driver = nonebot.get_driver()
driver.register_adapter(TelegramAdapter)

nonebot.load_builtin_plugins("echo")
nonebot.load_plugins("plugins")

if __name__ == "__main__":
    nonebot.logger.warning("Always use `nb run` to start the bot instead of manually running!")
    nonebot.run(app="__mp_main__:app")

其中一次报错

使用虚拟环境: C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\Scripts\python.exe
04-04 05:35:52 [SUCCESS] nonebot | NoneBot is initializing...
04-04 05:35:52 [INFO] nonebot | Current Env: prod
04-04 05:35:52 [SUCCESS] nonebot | Succeeded to load plugin "echo" from "nonebot.plugins.echo"
04-04 05:35:52 [SUCCESS] nonebot | Succeeded to load plugin "reply" from "plugins.reply"
04-04 05:35:52 [WARNING] __main__ | Always use `nb run` to start the bot instead of manually running!
04-04 05:35:52 [SUCCESS] nonebot | Running NoneBot...
04-04 05:35:52 [INFO] uvicorn | Started server process [9768]
04-04 05:35:52 [INFO] uvicorn | Waiting for application startup.
04-04 05:35:52 [INFO] nonebot | Telegram | Delete old webhook
04-04 05:35:52 [INFO] uvicorn | Application startup complete.
04-04 05:35:52 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit)
04-04 05:36:13 [ERROR] nonebot | Telegram | Setup for bot 5951329903 failed
Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\anyio\_core\_sockets.py", line 164, in try_connect
    stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\anyio\_backends\_asyncio.py", line 1691, in connect_tcp
    await get_running_loop().create_connection(
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 1025, in create_connection
    raise exceptions[0]
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "C:\Software\anaconda\lib\asyncio\proactor_events.py", line 702, in sock_connect
    return await self._proactor.connect(sock, address)
  File "C:\Software\anaconda\lib\asyncio\windows_events.py", line 812, in _poll
    value = callback(transferred, key, ov)
  File "C:\Software\anaconda\lib\asyncio\windows_events.py", line 599, in finish_connect
    ov.getresult()
OSError: [WinError 121] 信号灯超时时间已到

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

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_exceptions.py", line 10, in map_exceptions
    yield
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\backends\asyncio.py", line 111, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\anyio\_core\_sockets.py", line 222, in connect_tcp
    raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 60, in map_httpcore_exceptions
    yield
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection_pool.py", line 253, in handle_async_request
    raise exc
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection.py", line 86, in handle_async_request
    raise exc
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection.py", line 63, in handle_async_request
    stream = await self._connect(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection.py", line 111, in _connect
    stream = await self._network_backend.connect_tcp(**kwargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\backends\auto.py", line 29, in connect_tcp
    return await self._backend.connect_tcp(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\backends\asyncio.py", line 111, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "C:\Software\anaconda\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc)
httpcore.ConnectError: All connection attempts failed

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

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 228, in _call_api
    response = await self.request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\adapter\adapter.py", line 89, in request
    return await self.driver.request(setup)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\drivers\httpx.py", line 56, in request
    response = await client.request(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1533, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1620, in send
    response = await self._send_handling_auth(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1648, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1685, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1722, in _send_single_request
    response = await transport.handle_async_request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "C:\Software\anaconda\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed

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

Traceback (most recent call last):
  File "bot.py", line 15, in <module>
    nonebot.run(app="__mp_main__:app")
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\__init__.py", line 309, in run
    get_driver().run(*args, **kwargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\drivers\fastapi.py", line 198, in run
    uvicorn.run(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\uvicorn\main.py", line 568, in run
    server.run()
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\uvicorn\server.py", line 59, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Software\anaconda\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 603, in run_until_complete
    self.run_forever()
  File "C:\Software\anaconda\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 570, in run_forever
    self._run_once()
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 1859, in _run_once
    handle._run()
  File "C:\Software\anaconda\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
> File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 101, in poll
    await bot.delete_webhook()
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\bot.py", line 42, in call_api
    sign.return_annotation, await super().call_api(api, **kargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 120, in call_api
    raise exception
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 244, in _call_api
    raise NetworkError("HTTP request failed") from e
nonebot.adapters.telegram.exception.NetworkError: <NetWorkError message=HTTP request failed>
@j1g5awi j1g5awi self-assigned this Apr 4, 2023
@j1g5awi
Copy link
Member

j1g5awi commented Apr 4, 2023

我无法复现此问题,請說明你的 Python 版本以及 httpx 的版本,如果可以的话把 python 环境的 lock 文件打包给我。

@TheLZY
Copy link
Author

TheLZY commented Apr 5, 2023

python==3.8.13
httpx==0.23.3

poetry.zip

也有可能是我的小插件的问题?一旦它raise error,几分钟之内就开始弹networkerror
但是不一定,因为不是每次都这样
顺便venv里面的全部版本(

pip list
Package                  Version
------------------------ ------------
aiohttp                  3.8.4
aiosignal                1.3.1
anyio                    3.6.2
async-timeout            4.0.2
attrs                    22.2.0
certifi                  2022.12.7
charset-normalizer       3.1.0
click                    8.1.3
colorama                 0.4.6
fastapi                  0.95.0
frozenlist               1.3.3
h11                      0.14.0
h2                       4.1.0
hpack                    4.0.0
httpcore                 0.16.3
httptools                0.5.0
httpx                    0.23.3
hyperframe               6.0.1
idna                     3.4
loguru                   0.6.0
multidict                6.0.4
nonebot-adapter-telegram 0.1.0b9
nonebot2                 2.0.0rc4
openai                   0.27.3
Pillow                   9.5.0
pip                      23.0.1
pydantic                 1.10.7
pygtrie                  2.5.0
pypng                    0.20220715.0
python-dotenv            1.0.0
PyYAML                   6.0
qrcode                   7.4.2
regex                    2023.3.23
requests                 2.28.2
rfc3986                  1.5.0
setuptools               65.6.3
sniffio                  1.3.0
starlette                0.26.1
tiktoken                 0.3.3
tomli                    2.0.1
tqdm                     4.65.0
typing_extensions        4.5.0
urllib3                  1.25.11
uvicorn                  0.21.1
watchfiles               0.19.0
websockets               11.0
wheel                    0.38.4
win32-setctime           1.1.0
yarl                     1.8.2

@TheLZY
Copy link
Author

TheLZY commented Apr 5, 2023

( 怪了,怎么感觉真是我的小插件引起的
不过有时候又能用。就很迷

但是一旦有报错,就会一直报错,按啥都取消不了,包括 Crtl + C
😥

刚刚的日志


04-05 03:17:32 [SUCCESS] nonebot | Telegram 5951329903 | [message.group]: Message 90 from 1992278307@[Chat -1001608378252]: 团子你好呀
04-05 03:17:32 [INFO] nonebot | Event will be handled by Matcher(type='message', module=plugins.tuan-chatgpt)
04-05 03:17:55 [INFO] nonebot | Matcher(type='message', module=plugins.tuan-chatgpt) running complete
04-05 03:17:55 [ERROR] nonebot | Running Matcher(type='message', module=plugins.tuan-chatgpt) failed.
Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\anyio\_core\_sockets.py", line 164, in try_connect
    stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\anyio\_backends\_asyncio.py", line 1691, in connect_tcp
    await get_running_loop().create_connection(
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 1025, in create_connection
    raise exceptions[0]
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "C:\Software\anaconda\lib\asyncio\proactor_events.py", line 702, in sock_connect
    return await self._proactor.connect(sock, address)
  File "C:\Software\anaconda\lib\asyncio\windows_events.py", line 812, in _poll
    value = callback(transferred, key, ov)
  File "C:\Software\anaconda\lib\asyncio\windows_events.py", line 599, in finish_connect
    ov.getresult()
OSError: [WinError 121] 信号灯超时时间已到

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

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_exceptions.py", line 10, in map_exceptions
    yield
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\backends\asyncio.py", line 111, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\anyio\_core\_sockets.py", line 222, in connect_tcp
    raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 60, in map_httpcore_exceptions
    yield
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection_pool.py", line 253, in handle_async_request
    raise exc
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection.py", line 86, in handle_async_request
    raise exc
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection.py", line 63, in handle_async_request
    stream = await self._connect(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection.py", line 111, in _connect
    stream = await self._network_backend.connect_tcp(**kwargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\backends\auto.py", line 29, in connect_tcp
    return await self._backend.connect_tcp(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\backends\asyncio.py", line 111, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "C:\Software\anaconda\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc)
httpcore.ConnectError: All connection attempts failed

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

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 208, in _call_api
    response = await self.request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\adapter\adapter.py", line 89, in request
    return await self.driver.request(setup)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\drivers\httpx.py", line 56, in request
    response = await client.request(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1533, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1620, in send
    response = await self._send_handling_auth(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1648, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1685, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1722, in _send_single_request
    response = await transport.handle_async_request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "C:\Software\anaconda\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed

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

Traceback (most recent call last):
  File "bot.py", line 15, in <module>
    nonebot.run(app="__mp_main__:app")
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\__init__.py", line 309, in run
    get_driver().run(*args, **kwargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\drivers\fastapi.py", line 198, in run
    uvicorn.run(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\uvicorn\main.py", line 568, in run
    server.run()
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\uvicorn\server.py", line 59, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Software\anaconda\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 603, in run_until_complete
    self.run_forever()
  File "C:\Software\anaconda\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 570, in run_forever
    self._run_once()
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 1859, in _run_once
    handle._run()
  File "C:\Software\anaconda\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\message.py", line 141, in _check_matcher
    await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
> File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\message.py", line 187, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 753, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 728, in simple_run
    await handler(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\dependencies\__init__.py", line 108, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\plugins\tuan-chatgpt\__init__.py", line 149, in main_chat
    await chat_service.finish(answer)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 481, in finish
    await cls.send(message, **kwargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\matcher\matcher.py", line 466, in send
    return await bot.send(event=event, message=_message, **kwargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\bot.py", line 116, in send
    return await self.send_message(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\bot.py", line 74, in call_api
    sign.return_annotation, await super().call_api(api, **kargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 120, in call_api
    raise exception
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 224, in _call_api
    raise NetworkError("HTTP request failed") from e
nonebot.adapters.telegram.exception.NetworkError: <NetWorkError message=HTTP request failed>
04-05 03:18:03 [INFO] uvicorn | Shutting down
04-05 03:18:03 [INFO] uvicorn | Finished server process [19184]
04-05 03:18:03 [ERROR] nonebot | Telegram | Get updates for bot 5951329903 failed
anyio._backends._asyncio.ExceptionGroup: 0 exceptions were raised in the task group:
----------------------------


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

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_exceptions.py", line 10, in map_exceptions
    yield
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\backends\asyncio.py", line 111, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\anyio\_core\_sockets.py", line 222, in connect_tcp
    raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 60, in map_httpcore_exceptions
    yield
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection_pool.py", line 253, in handle_async_request
    raise exc
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection.py", line 86, in handle_async_request
    raise exc
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection.py", line 63, in handle_async_request
    stream = await self._connect(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_async\connection.py", line 111, in _connect
    stream = await self._network_backend.connect_tcp(**kwargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\backends\auto.py", line 29, in connect_tcp
    return await self._backend.connect_tcp(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\backends\asyncio.py", line 111, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "C:\Software\anaconda\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc)
httpcore.ConnectError: All connection attempts failed

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

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 208, in _call_api
    response = await self.request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\adapter\adapter.py", line 89, in request
    return await self.driver.request(setup)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\drivers\httpx.py", line 56, in request
    response = await client.request(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1533, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1620, in send
    response = await self._send_handling_auth(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1648, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1685, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_client.py", line 1722, in _send_single_request
    response = await transport.handle_async_request(request)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "C:\Software\anaconda\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\httpx\_transports\default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed

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

Traceback (most recent call last):
  File "bot.py", line 15, in <module>
    nonebot.run(app="__mp_main__:app")
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\__init__.py", line 309, in run
    get_driver().run(*args, **kwargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\drivers\fastapi.py", line 198, in run
    uvicorn.run(
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\uvicorn\main.py", line 568, in run
    server.run()
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\uvicorn\server.py", line 59, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Software\anaconda\lib\asyncio\runners.py", line 47, in run
    _cancel_all_tasks(loop)
  File "C:\Software\anaconda\lib\asyncio\runners.py", line 62, in _cancel_all_tasks
    loop.run_until_complete(
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 603, in run_until_complete
    self.run_forever()
  File "C:\Software\anaconda\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 570, in run_forever
    self._run_once()
  File "C:\Software\anaconda\lib\asyncio\base_events.py", line 1859, in _run_once
    handle._run()
  File "C:\Software\anaconda\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
> File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 74, in poll
    updates = await bot.get_updates(offset=update_offset, timeout=30)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\bot.py", line 74, in call_api
    sign.return_annotation, await super().call_api(api, **kargs)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 120, in call_api
    raise exception
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\.venv\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 224, in _call_api
    raise NetworkError("HTTP request failed") from e

@j1g5awi
Copy link
Member

j1g5awi commented Apr 5, 2023

你是否使用代理访问 Telegram?如果是你需要自行配置 telegram_proxy,因为 python38 并不会使用系统代理。

@TheLZY
Copy link
Author

TheLZY commented Apr 5, 2023

应该不是代理的问题,机子在国外来着

感觉和我的小插件可能有点关系
只要一 fail,就会整个崩掉
但是有时候不fail,只要bot挂着,过一会儿还是会崩?

04-05 14:22:36 [SUCCESS] nonebot | Telegram 5951329903 | [message.group]: Message 118 from 1992278307@[Chat -1001608378252]: 团子团子,唱一首许嵩的清明雨上听听
04-05 14:22:36 [INFO] nonebot | Event will be handled by Matcher(type='message', module=plugins.tuan-chatgpt)
04-05 14:23:05 [INFO] nonebot | Matcher(type='message', module=plugins.tuan-chatgpt) running complete
04-05 14:23:05 [ERROR] nonebot | Running Matcher(type='message', module=plugins.tuan-chatgpt) failed.
Traceback (most recent call last):
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\anyio\_core\_sockets.py", line 164, in try_connect
    stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\anyio\_backends\_asyncio.py", line 1691, in connect_tcp
    await get_running_loop().create_connection(
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\base_events.py", line 1065, in create_connection
    raise exceptions[0]
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\base_events.py", line 1050, in create_connection
    sock = await self._connect_sock(
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\base_events.py", line 961, in _connect_sock
    await self.sock_connect(sock, address)
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\proactor_events.py", line 703, in sock_connect
    return await self._proactor.connect(sock, address)
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\windows_events.py", line 817, in _poll
    value = callback(transferred, key, ov)
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\windows_events.py", line 604, in finish_connect
    ov.getresult()
OSError: [WinError 121] 信号灯超时时间已到

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

Traceback (most recent call last):
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\_exceptions.py", line 10, in map_exceptions
    yield
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\backends\asyncio.py", line 111, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\anyio\_core\_sockets.py", line 222, in connect_tcp
    raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpx\_transports\default.py", line 60, in map_httpcore_exceptions
    yield
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\_async\connection_pool.py", line 253, in handle_async_request
    raise exc
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\_async\connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(request)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\_async\connection.py", line 86, in handle_async_request
    raise exc
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\_async\connection.py", line 63, in handle_async_request
    stream = await self._connect(request)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\_async\connection.py", line 111, in _connect
    stream = await self._network_backend.connect_tcp(**kwargs)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\backends\auto.py", line 29, in connect_tcp
    return await self._backend.connect_tcp(
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\backends\asyncio.py", line 111, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "C:\Software\anaconda\envs\debug_py39\lib\contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc)
httpcore.ConnectError: All connection attempts failed

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

Traceback (most recent call last):
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 208, in _call_api
    response = await self.request(request)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\internal\adapter\adapter.py", line 89, in request
    return await self.driver.request(setup)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\drivers\httpx.py", line
 56, in request
    response = await client.request(
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpx\_client.py", line 1533, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpx\_client.py", line 1620, in send
    response = await self._send_handling_auth(
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpx\_client.py", line 1648, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpx\_client.py", line 1685, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpx\_client.py", line 1722, in _send_single_request
    response = await transport.handle_async_request(request)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "C:\Software\anaconda\envs\debug_py39\lib\contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpx\_transports\default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed

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

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\bot.py", line 15, in <module>
    nonebot.run(app="__mp_main__:app")
 ...
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 224, in _call_api
    raise NetworkError("HTTP request failed") from e
nonebot.adapters.telegram.exception.NetworkError: <NetWorkError message=HTTP request failed>
04-05 14:23:07 [INFO] uvicorn | Shutting down
04-05 14:23:07 [INFO] uvicorn | Finished server process [28592]
04-05 14:23:07 [ERROR] nonebot | Telegram | Get updates for bot 5951329903 failed
anyio._backends._asyncio.ExceptionGroup: 0 exceptions were raised in the task group:
----------------------------


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

Traceback (most recent call last):
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\_exceptions.py", line 10, in map_exceptions
    yield
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\backends\asyncio.py", line 111, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\anyio\_core\_sockets.py", line 222, in connect_tcp
    raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpx\_transports\default.py", line 60, in map_httpcore_exceptions
    yield
  ...
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc)
httpcore.ConnectError: All connection attempts failed
...

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

Traceback (most recent call last):
  File "C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram\bot.py", line 15, in <module>
    nonebot.run(app="__mp_main__:app")
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\__init__.py", line 309, in run
    get_driver().run(*args, **kwargs)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\drivers\fastapi.py", line 198, in run
    uvicorn.run(
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\uvicorn\main.py", line 568, in run
    server.run()
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\uvicorn\server.py", line 59, in
 run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\runners.py", line 47, in run
    _cancel_all_tasks(loop)
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\runners.py", line 63, in _cancel_all_tasks
    loop.run_until_complete(
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\base_events.py", line 634, in run_until_complete
    self.run_forever()
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\base_events.py", line 601, in run_forever
    self._run_once()
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\base_events.py", line 1905, in _run_once
    handle._run()
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
> File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 74, in poll
    updates = await bot.get_updates(offset=update_offset, timeout=30)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\adapters\telegram\bot.py", line 74, in call_api
    sign.return_annotation, await super().call_api(api, **kargs)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\internal\adapter\bot.py", line 120, in call_api
    raise exception
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 224, in _call_api
    raise NetworkError("HTTP request failed") from e
nonebot.adapters.telegram.exception.NetworkError: <NetWorkError message=HTTP request failed>

然后再打开就会这样,变ssl的问题了?

(debug_py39) C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram>nb run
04-05 14:28:55 [SUCCESS] nonebot | NoneBot is initializing...
04-05 14:28:55 [INFO] nonebot | Current Env: prod
04-05 14:28:55 [SUCCESS] nonebot | Succeeded to load plugin "echo" from "nonebot.plugins.echo"
04-05 14:28:55 [INFO] show_python | 使用 Python 3.9.16 (main, Mar  8 2023, 10:39:24) [MSC v.1916 64 bit (AMD64)]
04-05 14:28:55 [SUCCESS] nonebot | Succeeded to load plugin "show_python" from "plugins.show_python"
04-05 14:28:55 [SUCCESS] nonebot | Succeeded to load plugin "reply" from "plugins.reply"
04-05 14:28:56 [SUCCESS] nonebot | Succeeded to load plugin "tuan-chatgpt" from "plugins.tuan-chatgpt"
04-05 14:28:56 [WARNING] __main__ | Always use `nb run` to start the bot instead of manually running!
04-05 14:28:56 [SUCCESS] nonebot | Running NoneBot...
04-05 14:28:56 [INFO] uvicorn | Started server process [16184]
04-05 14:28:56 [INFO] uvicorn | Waiting for application startup.
04-05 14:28:56 [INFO] uvicorn | Application startup complete.
04-05 14:28:56 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:23333 (Press CTRL+C to quit)
04-05 14:28:56 [ERROR] nonebot | Telegram | Setup for bot 5951329903 failed
Traceback (most recent call last):
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 208, in _call_api
    response = await self.request(request)
  ...
  File "C:\Software\anaconda\envs\debug_py39\lib\ssl.py", line 945, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'api.telegram.org'. (_ssl.c:1129)

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

然后每次打开都会报这个ssl的错,只有注释掉 nonebot.load_plugins("plugins") 才能够停止报错

不过有时候成功了也会崩掉

04-05 15:09:53 [SUCCESS] nonebot | Telegram 5951329903 | [message.private]: Message 909 from 1992278307: 团子团子,唱一首许嵩的清明雨上听听
04-05 15:09:53 [INFO] nonebot | Event will be handled by Matcher(type='message', module=plugins.tuan-chatgpt)
04-05 15:10:21 [ERROR] tuan-chatgpt | 渲染图片时出错,报错 type object 'MessageSegment' has no attribute 'image'
04-05 15:10:21 [INFO] nonebot | Matcher(type='message', module=plugins.tuan-chatgpt) running complete
04-05 15:13:12 [ERROR] nonebot | Telegram | Get updates for bot 5951329903 failed
Traceback (most recent call last):
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\anyio\_core\_sockets.py", line 164, in try_connect
    stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\anyio\_backends\_asyncio.py", line 1691, in connect_tcp
    await get_running_loop().create_connection(
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\base_events.py", line 1065, in create_connection
    raise exceptions[0]
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\base_events.py", line 1050, in create_connection
    sock = await self._connect_sock(
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\base_events.py", line 961, in _connect_sock
    await self.sock_connect(sock, address)
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\proactor_events.py", line 703, in sock_connect
    return await self._proactor.connect(sock, address)
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\windows_events.py", line 817, in _poll
    value = callback(transferred, key, ov)
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\windows_events.py", line 604, in finish_connect
    ov.getresult()
OSError: [WinError 121] 信号灯超时时间已到

然后试了一下什么插件都不加载,放一会儿也会崩
注释掉 nonebot.load_plugins("plugins") 后运行:

(debug_py39) C:\Files\Code\QQbot\Chatgpt_test\telegram_bot_2\telegram>nb run
04-05 15:28:40 [SUCCESS] nonebot | NoneBot is initializing...
04-05 15:28:40 [INFO] nonebot | Current Env: prod
04-05 15:28:40 [SUCCESS] nonebot | Succeeded to load plugin "echo" from "nonebot.plugins.echo"
04-05 15:28:40 [WARNING] __main__ | Always use `nb run` to start the bot instead of manually running!
04-05 15:28:40 [SUCCESS] nonebot | Running NoneBot...
04-05 15:28:40 [INFO] uvicorn | Started server process [12568]
04-05 15:28:40 [INFO] uvicorn | Waiting for application startup.
04-05 15:28:40 [INFO] uvicorn | Application startup complete.
04-05 15:28:40 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:23333 (Press CTRL+C to quit)
04-05 15:28:41 [INFO] nonebot | Telegram | Delete old webhook
04-05 15:28:41 [INFO] nonebot | Telegram | Start poll
04-05 15:28:51 [SUCCESS] nonebot | Telegram 5951329903 | [message.private]: Message 923 from 1992278307: /echo hello
04-05 15:28:51 [INFO] nonebot | Event will be handled by Matcher(type='message', module=nonebot.plugins.echo)
04-05 15:28:51 [INFO] nonebot | Matcher(type='message', module=nonebot.plugins.echo) running complete
04-05 15:32:04 [SUCCESS] nonebot | Telegram 5951329903 | [message.private]: Message 925 from 1992278307: /echo hello
04-05 15:32:04 [INFO] nonebot | Event will be handled by Matcher(type='message', module=nonebot.plugins.echo)
04-05 15:32:04 [INFO] nonebot | Matcher(type='message', module=nonebot.plugins.echo) running complete
04-05 15:35:36 [ERROR] nonebot | Telegram | Get updates for bot 5951329903 failed
Traceback (most recent call last):
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\proactor_events.py", line 280, in _loop_reading
    data = fut.result()
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\windows_events.py", line 817, in _poll
    value = callback(transferred, key, ov)
  File "C:\Software\anaconda\envs\debug_py39\lib\asyncio\windows_events.py", line 462, in finish_recv
    return ov.getresult()
OSError: [WinError 121] 信号灯超时时间已到

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

Traceback (most recent call last):
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\httpcore\_exceptions.py", line 10, in map_exceptions
    yield
...
  File "C:\Software\anaconda\envs\debug_py39\lib\site-packages\nonebot\adapters\telegram\adapter.py", line 224, in _call_api
    raise NetworkError("HTTP request failed") from e
nonebot.adapters.telegram.exception.NetworkError: <NetWorkError message=HTTP request failed>
04-05 15:35:38 [INFO] uvicorn | Shutting down
04-05 15:35:38 [INFO] uvicorn | Finished server process [12568]
04-05 15:35:38 [ERROR] nonebot | Telegram | Get updates for bot 5951329903 failed
anyio._backends._asyncio.ExceptionGroup: 0 exceptions were raised in the task group:
----------------------------


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

可以看到三分钟就崩了
不过有时候又不会。怪了怪了

总结下来就是插件的fail会引发整个机器人的崩掉,但是就算不转插件过一会儿自己也有会崩?

所以我猜测主要的问题是,一个插件fail了之后,因为是串行处理的,所以就会一直卡在这里?重启之后也一样?
Get updates for bot 5951329903 failed 以及重启后的 [ERROR] nonebot | Telegram | Setup for bot 5951329903 failed

(而且,在qq上使用的时候这个插件是没有问题的,而且就算是在telegram上有时候这个插件又是正常的,就很迷)

次要的问题是有些时候他自己会断开连接?
而且断开连接之后会自动重连,这时候按 Crtl + C,只会关闭一个uvicorn,但是还是会一直自动重连,cmd里面就会一直弹弹弹弹弹,按什么都关不了

大佬您要整个项目的打包试试吗(虽然我插件就装了3个,一个示例reply,一个回复python版本和一个我的连接openai的小插件

@j1g5awi
Copy link
Member

j1g5awi commented Apr 6, 2023

八成是 openai 的问题,qq 不出错是因为 OneBot V11 走的 websocket 通信。

@tolatolatop
Copy link

Apr 21 21:48:10 slave nb[29214]: The above exception was the direct cause of the following exception:
Apr 21 21:48:10 slave nb[29214]: Traceback (most recent call last):
Apr 21 21:48:10 slave nb[29214]:   File "/home/pi/app/rockbot/rockbot/rock_bot/bot.py", line 18, in <module>
Apr 21 21:48:10 slave nb[29214]:     nonebot.run()
Apr 21 21:48:10 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/nonebot/__init__.py", line 309, in run
Apr 21 21:48:10 slave nb[29214]:     get_driver().run(*args, **kwargs)
Apr 21 21:48:10 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/nonebot/drivers/fastapi.py", line 198, in run
Apr 21 21:48:10 slave nb[29214]:     uvicorn.run(
Apr 21 21:48:10 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/uvicorn/main.py", line 568, in run
Apr 21 21:48:10 slave nb[29214]:     server.run()
Apr 21 21:48:10 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/uvicorn/server.py", line 59, in run
Apr 21 21:48:10 slave nb[29214]:     return asyncio.run(self.serve(sockets=sockets))
Apr 21 21:48:10 slave nb[29214]:   File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
Apr 21 21:48:10 slave nb[29214]:     return loop.run_until_complete(main)
Apr 21 21:48:10 slave nb[29214]: > File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/nonebot/adapters/telegram/adapter.py", line 74, in poll
Apr 21 21:48:10 slave nb[29214]:     updates = await bot.get_updates(offset=update_offset, timeout=30)
Apr 21 21:48:10 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/nonebot/adapters/telegram/bot.py", line 91, in call_api
Apr 21 21:48:10 slave nb[29214]:     sign.return_annotation, await super().call_api(api, **kargs)
Apr 21 21:48:10 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/nonebot/internal/adapter/bot.py", line 120, in call_api
Apr 21 21:48:10 slave nb[29214]:     raise exception
Apr 21 21:48:10 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/nonebot/internal/adapter/bot.py", line 98, in call_api
Apr 21 21:48:10 slave nb[29214]:     result = await self.adapter._call_api(self, api, **data)
Apr 21 21:48:10 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/nonebot/adapters/telegram/adapter.py", line 224, in _call_api
Apr 21 21:48:10 slave nb[29214]:     raise NetworkError("HTTP request failed") from e
Apr 21 21:48:10 slave nb[29214]: nonebot.adapters.telegram.exception.NetworkError: <NetWorkError message=HTTP request failed>
Apr 21 21:50:23 slave nb[29214]: 04-21 21:50:23 [ERROR] nonebot | Telegram | Get updates for bot 5920124283 failed
Apr 21 21:50:23 slave nb[29214]: Traceback (most recent call last):
Apr 21 21:50:23 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 164, in try_connect
Apr 21 21:50:23 slave nb[29214]:     stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
Apr 21 21:50:23 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 1691, in connect_tcp
Apr 21 21:50:23 slave nb[29214]:     await get_running_loop().create_connection(
Apr 21 21:50:23 slave nb[29214]:   File "uvloop/loop.pyx", line 2039, in create_connection
Apr 21 21:50:23 slave nb[29214]:     raise exceptions[0]
Apr 21 21:50:23 slave nb[29214]:   File "uvloop/loop.pyx", line 2016, in uvloop.loop.Loop.create_connection
Apr 21 21:50:23 slave nb[29214]:     await waiter
Apr 21 21:50:23 slave nb[29214]: TimeoutError: [Errno 110] Connection timed out
Apr 21 21:50:23 slave nb[29214]: The above exception was the direct cause of the following exception:
Apr 21 21:50:23 slave nb[29214]: Traceback (most recent call last):
Apr 21 21:50:23 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
Apr 21 21:50:23 slave nb[29214]:     yield
Apr 21 21:50:23 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 111, in connect_tcp
Apr 21 21:50:23 slave nb[29214]:     stream: anyio.abc.ByteStream = await anyio.connect_tcp(
Apr 21 21:50:23 slave nb[29214]:   File "/home/pi/app/rockbot/venv/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 222, in connect_tcp
Apr 21 21:50:23 slave nb[29214]:     raise OSError("All connection attempts failed") from cause
Apr 21 21:50:23 slave nb[29214]: OSError: All connection attempts failed

python 3.9.2有同样问题 也装了openai的插件。

Bot能正常使用,错误一般出现在交互结束后的一段时间内。怀疑和插件用法以及Telegram API会话超时有关。

@NormanBB
Copy link

NormanBB commented Jul 8, 2023

Python 版本:3.11.3
适配器版本:0.1.0b14
使用插件:官方示例的 weather
httpx 版本: 0.24.1
使用代理访问,切换了代理之后似乎问题解决了,有可能为代理的问题吗?

在响应了一次命令后bot 立刻崩溃。附 原始项目文件

点击查看
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpx\_transports\default.py", line 60, in map_httpcore_exceptions
    yield
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpx\_transports\default.py", line 353, in handle_async_request
    resp = await self._pool.handle_async_request(req)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpcore\_async\connection_pool.py", line 262, in handle_async_request
    raise exc
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpcore\_async\connection_pool.py", line 245, in handle_async_request
    response = await connection.handle_async_request(request)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpcore\_async\http_proxy.py", line 326, in handle_async_request
    return await self._connection.handle_async_request(request)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpcore\_async\http11.py", line 121, in handle_async_request
    raise exc
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpcore\_async\http11.py", line 99, in handle_async_request
    ) = await self._receive_response_headers(**kwargs)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpcore\_async\http11.py", line 164, in _receive_response_headers
    event = await self._receive_event(timeout=timeout)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpcore\_async\http11.py", line 214, in _receive_event
    raise RemoteProtocolError(msg)
httpcore.RemoteProtocolError: Server disconnected without sending a response.

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

Traceback (most recent call last):
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\nonebot\adapters\telegram\adapter.py", line 226, in _call_api
    response = await self.request(request)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\nonebot\internal\adapter\adapter.py", line 89, in request
    return await self.driver.request(setup)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\nonebot\drivers\httpx.py", line 56, in request
    response = await client.request(
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpx\_client.py", line 1530, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpx\_client.py", line 1617, in send
    response = await self._send_handling_auth(
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpx\_client.py", line 1645, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpx\_client.py", line 1682, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpx\_client.py", line 1719, in _send_single_request
    response = await transport.handle_async_request(request)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpx\_transports\default.py", line 352, in handle_async_request
    with map_httpcore_exceptions():
  File "C:\Users\Arno\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\httpx\_transports\default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.RemoteProtocolError: Server disconnected without sending a response.

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

Traceback (most recent call last):
  File "c:\Users\Arno\Documents\Game\bot.py", line 15, in <module>
    nonebot.run(app="__mp_main__:app")
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\nonebot\__init__.py", line 309, in run
    get_driver().run(*args, **kwargs)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\nonebot\drivers\fastapi.py", line 198, in run
    uvicorn.run(
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\uvicorn\main.py", line 578, in run
    server.run()
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\uvicorn\server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Users\Arno\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
  File "C:\Users\Arno\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "C:\Users\Arno\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "C:\Users\Arno\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "C:\Users\Arno\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 607, in run_forever
    self._run_once()
  File "C:\Users\Arno\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1922, in _run_once
    handle._run()
  File "C:\Users\Arno\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
> File "C:\Users\Arno\Documents\Game\Lib\site-packages\nonebot\adapters\telegram\adapter.py", line 86, in poll
    updates = await bot.get_updates(offset=update_offset, timeout=30)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\nonebot\adapters\telegram\bot.py", line 103, in call_api
    sign.return_annotation, await super().call_api(api, **kargs)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\nonebot\internal\adapter\bot.py", line 120, in call_api
    raise exception
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "C:\Users\Arno\Documents\Game\Lib\site-packages\nonebot\adapters\telegram\adapter.py", line 228, in _call_api
    raise NetworkError("HTTP request failed") from e
nonebot.adapters.telegram.exception.NetworkError: <NetWorkError message=HTTP request failed>

@j1g5awi
Copy link
Member

j1g5awi commented Jul 8, 2023

@NormanBB 你是代理的问题,与本 Issue 无关。

@hackzy
Copy link

hackzy commented Aug 1, 2023

Traceback (most recent call last):
File "C:\Users\joker\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 792, in _loop_self_reading
f.result() # may raise
^^^^^^^^^^
File "C:\Users\joker\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 846, in _poll
value = callback(transferred, key, ov)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\joker\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 471, in finish_recv
return ov.getresult()
^^^^^^^^^^^^^^
OSError: [WinError 121] 信号灯超时时间已到

同样的问题 挂着没多久就突然报错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants