Python视频不是通过使用modu请求下载的

2024-04-26 10:09:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个Python(3.6)和Django(2)项目,在这个项目中,我需要从一个URL下载一个视频。 以下是我尝试过的:

来自视图.py:

    if validation is True:
        url = request.POST.get('video_url')
        r = requests.get(url, allow_redirects=True)
        file = open('my_video.mp4', 'wb').write(r.content)
        rea_response = HttpResponse(file, content_type='video/mp4')
        rea_response['Content-Disposition'] = 'attachment; filename=my_video.mp4'
        return rea_response

下载视频的网址是:

https://expirebox.com/files/386713962c5f8b7556bc77c4a6c2a576.mp4

它下载了一个名为my_video.mp4的文件,但是当我试图打开这个视频时,它没有播放。你知道吗

我的代码有什么问题? 或者有没有更好的方法从URL下载视频。你知道吗


Tags: 项目django视图trueurlget视频response