aiogram bot TelegramNetworkError:HTTP 客户端显示 - 请求超时错误

问题描述 投票:0回答:1
我有一个带有启动命令处理程序的简单机器人:

@user_router.message(CommandStart()) async def start_command(message: Message): logger.info(f'Start from user {message.from_user.username} id={message.from_user.id}') await message.answer('Hello')
当我运行机器人时,我得到通常的正常日志:

[2024-07-29 20:04:09,944] #INFO bot.py:21 - __main__ - Starting bot [2024-07-29 20:04:10,731] #INFO dispatcher.py:527 - aiogram.dispatcher - Start polling [2024-07-29 20:04:11,034] #INFO dispatcher.py:341 - aiogram.dispatcher - Run polling for bot ....
按下启动命令后 - 我收到错误 aiogram.exceptions.TelegramNetworkError: HTTP Client 说 - 请求超时错误:

[2024-07-29 20:04:15,519] #INFO user_handlers.py:23 - handlers.user_handlers - Start from user ..... [2024-07-29 20:05:15,969] #INFO dispatcher.py:172 - aiogram.event - Update id=.... is not handled. Duration 60449 ms by bot id=.... [2024-07-29 20:05:15,970] #ERROR dispatcher.py:315 - aiogram.event - Cause exception while process update id=..... by bot id=.... TelegramNetworkError: HTTP Client says - Request timeout error Traceback (most recent call last): File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/client/session/aiohttp.py", line 181, in make_request async with session.post( File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiohttp/client.py", line 1197, in __aenter__ self._resp = await self._coro ^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiohttp/client.py", line 507, in _request with timer: File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiohttp/helpers.py", line 735, in __exit__ raise asyncio.TimeoutError from None TimeoutError During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/dispatcher.py", line 309, in _process_update response = await self.feed_update(bot, update, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/dispatcher.py", line 158, in feed_update response = await self.update.wrap_outer_middleware( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/middlewares/error.py", line 25, in __call__ return await handler(event, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/middlewares/user_context.py", line 49, in __call__ return await handler(event, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/fsm/middleware.py", line 42, in __call__ return await handler(event, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/event/telegram.py", line 121, in trigger return await wrapped_inner(event, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/event/handler.py", line 43, in call return await wrapped() ^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/dispatcher.py", line 276, in _listen_update return await self.propagate_event(update_type=update_type, event=event, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 142, in propagate_event return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 137, in _wrapped return await self._propagate_event( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 170, in _propagate_event response = await router.propagate_event(update_type=update_type, event=event, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 142, in propagate_event return await observer.wrap_outer_middleware(_wrapped, event=event, data=kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 137, in _wrapped return await self._propagate_event( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/router.py", line 162, in _propagate_event response = await observer.trigger(event, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/event/telegram.py", line 121, in trigger return await wrapped_inner(event, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/dispatcher/event/handler.py", line 43, in call return await wrapped() ^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/handlers/user_handlers.py", line 31, in start_command await message.answer(LEXICON_RU['greeting']) File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/methods/base.py", line 84, in emit return await bot(self) ^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/client/bot.py", line 485, in __call__ return await self.session(self, method, timeout=request_timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/client/session/base.py", line 254, in __call__ return cast(TelegramType, await middleware(bot, method)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/andreisukhar/Projects/Python/rulebreakers/she-bot/venv/lib/python3.12/site-packages/aiogram/client/session/aiohttp.py", line 186, in make_request raise TelegramNetworkError(method=method, message="Request timeout error") aiogram.exceptions.TelegramNetworkError: HTTP Client says - Request timeout error
我让我的朋友在他的计算机上运行 - 他一切正常并得到机器人的响应。

可能是什么?

python telegram-bot aiogram
1个回答
0
投票
我的 VDS 服务器上也遇到同样的问题。如果我同时有 3 个以上正在工作的轮询机器人,并且这些机器人正在使用请求 iohttp 请求 - 此异常会非常频繁地弹出。

如果您有超过 1 个正在运行的机器人\解析器 tc。 - 考虑为机器人使用 webhooks。工作更稳定。

© www.soinside.com 2019 - 2024. All rights reserved.