I am attempting to upload a sizable file using the local API Server, but I encounter a timeout error during the process. The specific error returned is aiogram.exceptions.TelegramNetworkError: HTTP Client says - Request timeout error. Here’s a portion of my code:
import asyncio
import logging
import sys
import json
from aiogram import Bot, Dispatcher, html
from aiogram.client.default import DefaultBotProperties
from aiogram.client import telegram
from aiogram.enums import ParseMode
from aiogram.filters import CommandStart
from aiogram.types import Message, FSInputFile
from aiogram.client.session.aiohttp import AiohttpSession
with open('config.json', 'r') as file:
config = json.load(file)
api_token = config['token']
session_instance = AiohttpSession(
api=telegram.TelegramAPIServer.from_base('http://127.0.0.1:4200')
)
dispatcher = Dispatcher()
@dispatcher.message()
async def file_sender_handler(message: Message) -> None:
with open('./files/large_video.mp4', 'rb') as video_file:
file_to_send = FSInputFile('./files/large_video.mp4')
await message.reply('Starting file upload...')
await message.reply_document(file_to_send)
async def run_bot() -> None:
bot = Bot(token=api_token, default=DefaultBotProperties(parse_mode=ParseMode.HTML), session=session_instance)
await dispatcher.start_polling(bot, polling_timeout=90)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
asyncio.run(run_bot())
The issue arises when I upload a 1.5 GB file. The program seems to initially copy the file to the local server before it begins the upload to Telegram. My internet connection has a bandwidth of 200 Mbit/s, so the server should be able to process it. However, after approximately 30 to 60 seconds, I receive the timeout error, even though the file manages to upload to Telegram after the program fails. The error traceback includes a TimeoutError occurring during the update processing. Can anyone suggest a solution?