nonebot / nonebot/adapter-telegram

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

Open
#24 10 comments 1 reaction 1 assignee View on GitHub

@j1g5awi is already working on this.

Since Apr 4, 2023.

Dominant language
Python
Stars
74
Forks
15
PR merge metrics
No merged PRs in 30d

Description

最近经常出现 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>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.