0

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

来自views.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

下载视频的 URL 是:

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

它会下载一个名为 as 的文件,my_video.mp4但是当我尝试打开此视频时,它没有播放。

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

4

0 回答 0