Ошибка при загрузке видео из ВК в aiogram

Всем привет. При попытке загрузить видео в Aiogram из VK (локально видео загружается исправно), выдаёт следующие сообщения в консоли, будто бот pooling запущен в два потока и при этом не загружается видео в чат бота.

Подскажите, что делаю не так? Файл с видео скачивается и запускается исправно.

введите сюда описание изображения

Пробовал использовать Aiogram InputField, но тоже не выходит.

`python
async def download_vk_video(url, output_path="vk_video.mp4"):
ydl_opts = {
    'outtmpl': output_path,
    'format': 'best',
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
    try:
        ydl.download([url])
    except Exception as e:
        logging.error(f"Ошибка при загрузке видео: {e}")


async def send_post_to_telegram(post):
text = post.get('text', '')
attachments = post.get('attachments', [])

if text:
    logging.info(f"Sending text: {text}")
    await bot.send_message(chat_id=CHAT_ID, text=text)

for attachment in attachments:
    if attachment['type'] == 'photo':
        pass

    elif attachment['type'] == 'video':
        video = attachment['video']
        video_id = f"{video['owner_id']}_{video['id']}"
        download_url = f"https://vk.com/video{video['owner_id']}_{video['id']}"
        video_filename = f"{video_id}.mp4"
        logging.info(f"Video download URL: {download_url}")

        await download_vk_video(download_url, video_filename)

        while not os.path.exists(video_filename) or os.path.exists(f"{video_filename}.part"):
            logging.info(f"Waiting for video download completion: {video_filename}")
            await asyncio.sleep(1)

        if os.path.exists(video_filename):
            logging.info(f"Sending video from file: {video_filename}")
            await bot.send_video(chat_id=CHAT_ID, video=video_filename)
            os.remove(video_filename)
        else:
            logging.error(f"Failed to download video to {video_filename}")`

Вывод в консоль

INFO:aiogram.dispatcher:Run polling for bot @ArmyPostUrl_bot id=76334534534 - 'Ножная Лавка'
INFO:root:Video download URL: https://vk.com/video-2######2_456239055
[vk] Extracting URL: https://vk.com/video-2######2_456239055
[vk] -228219752_456239055: Downloading JSON metadata
[vk] -228219752_456239055: Downloading MPD manifest
[vk] -228219752_456239055: Downloading m3u8 information
[info] -228219752_456239055: Downloading 1 format(s): url720
[download] Destination: -228219752_456239055.mp4
[download] 100% of   11.75MiB in 00:00:03 at 3.53MiB/s   
INFO:root:Sending video from file: -228219752_456239055.mp4
ERROR:aiogram.dispatcher:Failed to fetch updates - TelegramConflictError: Telegram server says - Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
WARNING:aiogram.dispatcher:Sleep for 1.000000 seconds and try again... (tryings = 0, bot id = 7639639669)
ERROR:root:Ошибка при получении событий Long Poll: Telegram server says - Bad Request: wrong HTTP URL specified
ERROR:aiogram.dispatcher:Failed to fetch updates - TelegramConflictError: Telegram server says - Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
WARNING:aiogram.dispatcher:Sleep for 1.288815 seconds and try again... (tryings = 1, bot id = 7639639669)
ERROR:aiogram.dispatcher:Failed to fetch updates - TelegramConflictError: Telegram server says - Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
WARNING:aiogram.dispatcher:Sleep for 1.775628 seconds and try again... (tryings = 2, bot id = 7639639669)
ERROR:aiogram.dispatcher:Failed to fetch updates - TelegramConflictError: Telegram server says - Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
WARNING:aiogram.dispatcher:Sleep for 2.247080 seconds and try again... (tryings = 3, bot id = 7639639669)
ERROR:aiogram.dispatcher:Failed to fetch updates - TelegramConflictError: Telegram server says - Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
WARNING:aiogram.dispatcher:Sleep for 2.720320 seconds and try again... (tryings = 4, bot id = 7639639669)
ERROR:aiogram.dispatcher:Failed to fetch updates - TelegramConflictError: Telegram server says - Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
WARNING:aiogram.dispatcher:Sleep for 3.578807 seconds and try again... (tryings = 5, bot id = 7639639669)
ERROR:aiogram.dispatcher:Failed to fetch updates - TelegramConflictError: Telegram server says - Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
WARNING:aiogram.dispatcher:Sleep for 4.573576 seconds and try again... (tryings = 6, bot id = 7639639669)```


Ответы (1 шт):

Автор решения: Kolhun

Решил вопрос завернув путь до видео в FSInputFile (aiogram.types) и это помогло. Видео теперь загружается исправно, правда проблема что бот работает на двух потоках pooling еще не исправлена. Может причина в том где вызываю check_longpoll_updates() с помощью asyncio.create_task() и одновременно запускаю dp.start_polling(bot)?

async def download_vk_video(url, output_path="vk_video.mp4"):
    ydl_opts = {
        'outtmpl': output_path,
        'format': 'best',
    }
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        ydl.download([url])


async def send_post_to_telegram(post):
    text = post.get('text', '')
    attachments = post.get('attachments', [])

    if text:
        await bot.send_message(chat_id=CHAT_ID, text=text)

    for attachment in attachments:
        if attachment['type'] == 'photo':
            photo_url = attachment['photo']['sizes'][-1]['url']
            await bot.send_photo(chat_id=CHAT_ID, photo=photo_url)
        elif attachment['type'] == 'video':
            video = attachment['video']
            video_id = f"{video['owner_id']}_{video['id']}"

            download_url = f"https://vk.com/video{video['owner_id']}_{video['id']}"
            video_filename = f"{video_id}.mp4"

            await download_vk_video(download_url, video_filename)

            while os.path.exists(f"{video_filename}.part"):
                await asyncio.sleep(1)

            if os.path.exists(video_filename) and os.path.getsize(video_filename) > 0:
                await bot.send_video(chat_id=CHAT_ID, video=FSInputFile(video_filename))
                os.remove(video_filename)
            else:
                logging.error(f"Ошибка: файл {video_filename} не найден или пуст.")```
→ Ссылка