anotherhax
@anotherhax
Программирую на Python

При использовании бота выдает непонятную ошибку Task exception was never retrieved?

Запускаю бота, при тестировании бот выдает эту ошибку и я не понимаю что с ней делать.
вот код бота:
import os, re
from pytube import YouTube
from pathlib import Path
from aiogram import *
from selenium import webdriver
import time
from bs4 import BeautifulSoup
import requests
from urllib.request import urlopen
from tiktok_api import *
bot = Bot('ТОКЕН')
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def start_message(message:types.Message):
    chat_id = message.chat.id
    await bot.send_message(chat_id, 'Привет, я - бот, который автоматически сохраняет видео, которые ты присылаешь, чтобы бот начал работать, тебе нужно всего лишь подписаться на эти каналы:\n'
                           'После чего просто отправь мне ссылку на видео и немного подожди.')
@dp.message_handler()
async def message_text(message:types.Message):
    chat_id = message.chat.id
    url = message.text
    yt = YouTube(url)
    if message.text.startswith == 'https://youtu.be/' or 'https://www.youtube.com/':
        await bot.send_message(chat_id, f'Начинаю загрузку видео: {yt.title}.\n'
                                        f'С канала: {yt.author}.', parse_mode='Markdown')
        await download_yt(url, message, bot)
    elif message.text.startswith == 'https://instagram.com/p/':
        await bot.send_message(chat_id, 'Начинаю загрузку видео... ', parse_mode='Markdown')
        await download_inst(url, message, bot)
    elif message.text.startswith == 'https://vm.tiktok.com/' or 'https://www.tiktok.com/':
        await bot.send_message(chat_id, 'Начинаю загрузку видео...', parse_mode='Markdown')
        await download_tik(url, message, bot)
async def download_yt(url, message, bot):
    yt = YouTube(url)
    stream = yt.streams.filter(progressive=True, file_extension='mp4')
    stream.get_highest_resolution().download(f'{message.chat.id}', f'{message.chat.id}_{yt.title}')
    with open(f'{message.chat.id}/{message.chat.id}_{yt.title}', 'rb') as video:
        await bot.send_video(message.chat.id, video, caption='Ваше видео.', parse_mode='Markdown')
        os.remove(f'{message.chat.id}/{message.chat.id}_{yt.title}')
        os.remove(f'{message.chat.id}')
async def download_inst(url, message, bot):
    try:
        response = requests.get(url=url)
        with open('videos/video.mp4', 'wb') as video:
            video.write(response.content)
        bot.send_video(message.chat.id, video, caption='Ваше видео.', parse_mode='Markdown')
        os.remove('videos/video.mp4')
    except Exception as e:
        bot.send_message(message.chat.id, 'Ошибка. Повтори попытку еще раз.', parse_mode='Markdown')
async def download_tik(url, message, bot):
    try:
        response = requests.get(url=url)
        with open('videos/video.mp4', 'wb') as video:
            video.write(response.content)
        bot.send_video(message.chat.id, video, caption='Ваше видео.', parse_mode='Markdown')
        os.remove('videos/video.mp4')
    except Exception as e:
        bot.send_message(message.chat.id, 'Ошибка. Повтори попытку еще раз.', parse_mode='Markdown')
if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)


Вот код ошибки:
Task exception was never retrieved
future: <Task finished name='Task-19' coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\kpacu\AppData\Local\Programs\Python\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=VideoUnavailable('71997977982 is unavailable')>
Traceback (most recent call last):
  File "C:\Users\kpacu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytube\__main__.py", line 341, in title
    self._title = self.vid_info['videoDetails']['title']
                  ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'videoDetails'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\kpacu\AppData\Local\Programs\Python\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kpacu\AppData\Local\Programs\Python\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
    return await asyncio.gather(*tasks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kpacu\AppData\Local\Programs\Python\Python311\Lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kpacu\AppData\Local\Programs\Python\Python311\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
    return await self.message_handlers.notify(update.message)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kpacu\AppData\Local\Programs\Python\Python311\Lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kpacu\Desktop\tg_bots\savebot\bot.py", line 24, in message_text
    await bot.send_message(chat_id, f'Начинаю загрузку видео: {yt.title}.\n'
                                                               ^^^^^^^^
  File "C:\Users\kpacu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytube\__main__.py", line 345, in title
    self.check_availability()
  File "C:\Users\kpacu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytube\__main__.py", line 231, in check_availability
    raise exceptions.VideoUnavailable(video_id=self.video_id)
pytube.exceptions.VideoUnavailable: 71997977982 is unavailable

Прошу помочь, я только начинаю программировать Telegram ботов. Спасибо.
  • Вопрос задан
  • 119 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы