Почему возвращает 500 ошибку?

Написал небольшое приложение на FastApi, которое скачивает и склеивает видео. Когда тестирую в swagger, все работает корректно. Составил http запрос из телеграм бота в приложение, скачивания видео происходит, до склейки дело не доходит, возвращает 500 ошибку.
Код API:
from fastapi import FastAPI, Query
from typing import List
from pytube import YouTube
from pytube.exceptions import RegexMatchError
import os
from schemas import Video
from moviepy.editor import VideoFileClip, concatenate_videoclips
from random import randint

MAIN_FOLDER = os.getcwd()
app = FastAPI()

@app.post('/video')
def create_video(item: Video):
    videos = []
    links= item.link
    for l in links:
        yt = YouTube(l)
        try:
            stream = yt.streams.filter(progressive=True, res="720p")[0]
            name = f"{yt.title.replace('.', '')}.mp4"   
            stream.download()
            videos.append(name.replace(':', '').replace('\'', '').replace('\\', '').replace('\"', '').replace('/', '').replace('#', ''))

                
        except IndexError:
            stream = yt.streams.filter(progressive=True)[0]
            name = f"{yt.title}.mp4"          
            stream.download()
            videos.append(name.replace(':', '').replace('\'', '').replace('\\', '').replace('\"', '').replace('/', ''))


        except RegexMatchError: # не работает, разобраться почему
            return "Загрузка не удалась, проверьте ссылки, либо повторите попытку позже"

    r_videos = []
    mp4 = []
    for file in os.listdir():
        if file.endswith(".mp4") and file in videos:
                mp4.append(file)
    print(videos)
    print(mp4)
    if len(mp4) > 0:
        for video in mp4:
            r_v = VideoFileClip(video)
            r_videos.append(r_v)
        try:
            final_clip = concatenate_videoclips(r_videos, method="compose")
            final_clip.write_videofile(f"{str(randint(1, 5000))}.mp4")
            for video in mp4:
                os.remove(video)
        except Exception as ex:
            print("Ничего не вышло :(")
            print(ex)
    else:
        return "Видео не добавлены"


Код обращения бота:
@dp.message_handler(state=StorageLink.links)
async def input_links(message: types.Message, state: FSMContext):
    async with state.proxy() as data:
        data['links'] = message.text.split('\n')
        test = data["links"]
    header = {"link": test}
    response = requests.post("http://127.0.0.1:8000/video", json=header)
    await bot.send_message(message.chat.id, response.status_code)

Как видно я принтую списки с видео перед склейкой, так вот в консоль ничего не приходит, даже пустые списки не показывает
  • Вопрос задан
  • 152 просмотра
Пригласить эксперта
Ваш ответ на вопрос

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

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