From ac2bd8f644109577cf8e843ed42be250e5772cf8 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Tue, 30 Jun 2026 20:31:37 +0000 Subject: [PATCH] fix(bot): retry admin video upload on transient httpx transport errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit send_video_to_admin_bot() had no retry, unlike the client-facing reply_video() path fixed earlier — a transient httpx.ReadError during upload silently dropped the admin copy while the user still got their video, since this function swallows its own exceptions. --- bot.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/bot.py b/bot.py index 222d62a..a66f24d 100644 --- a/bot.py +++ b/bot.py @@ -488,19 +488,30 @@ async def send_video_to_admin_bot(video_path: str, url: str, from_user=None): if user_info: caption += f"\n👤 {user_info}" - # Отправляем видео - with open(video_path, 'rb') as video_file: - await admin_bot.send_video( - chat_id=admin_chat_id, - video=video_file, - caption=caption, - supports_streaming=True, - read_timeout=600, - write_timeout=600, - connect_timeout=60, - pool_timeout=60 - ) - + # Отправляем видео (с ретраем — транспортные ошибки httpx при аплоаде бывают и здесь) + send_retries = 3 + for attempt in range(send_retries): + video_file = open(video_path, 'rb') + try: + await admin_bot.send_video( + chat_id=admin_chat_id, + video=video_file, + caption=caption, + supports_streaming=True, + read_timeout=600, + write_timeout=600, + connect_timeout=60, + pool_timeout=60 + ) + break + except Exception as send_error: + if attempt == send_retries - 1: + raise + logger.warning(f"Отправка видео админ боту: попытка {attempt + 1}/{send_retries} не удалась: {send_error}") + await asyncio.sleep((attempt + 1) * 2) + finally: + video_file.close() + logger.info(f"Видео отправлено админ боту: {video_path}") except Exception as e: