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

Неизвестная ошибка в aiogram, можете помочь понять в чем проблема?

Почему-то при запуске бота, при введении ссылки, через некоторое время вылезает непонятная ошибка и не дает боту ничего отправить.
Пишу на aiogram.
Вот код бота:
import os, re
from requests import *
from pytube import YouTube
from aiogram import *
import urllib.request
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, f'Начинаю загрузку видео... ', parse_mode='Markdown')
        await download_inst(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}')
async def download_inst(url, message, bot):
    pass
if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)

а вот код ошибки:
C:\Users\kpacu\AppData\Local\Programs\Python\Python311\python.exe C:\Users\kpacu\Desktop\tg_bots\savebot\bot.py 
Updates were skipped successfully.
Task exception was never retrieved
future: <Task finished name='Task-13' 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=OSError(22, 'Invalid argument')>
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 21, in message_text
    await download_yt(url, message, bot)
  File "C:\Users\kpacu\Desktop\tg_bots\savebot\bot.py", line 28, in download_yt
    stream.get_highest_resolution().download(f'{message.chat.id}', f'{message.chat.id}_{yt.title}')
  File "C:\Users\kpacu\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytube\streams.py", line 312, in download
    with open(file_path, "wb") as fh:
         ^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument: 'C:\\Users\\kpacu\\Desktop\\tg_bots\\savebot\\1390506311\\1390506311_Download Instagram Profile Pictures or Videos using Python | Instaloader Python Library'
  • Вопрос задан
  • 88 просмотров
Решения вопроса 1
phaggi
@phaggi
лужу, паяю, ЭВМы починяю
Элементарно: pipe |- запрещенный символ в именах файлов windows. Ошибка не бота, а системы.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

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