Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

django - Python video is not playing Downloaded by using requests module

I'm working on a Python(3.6) & Django(2) project in which I need to download a video from a URL. Here's what I have tried:

from 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

The URL from where it's downloading the vide is:

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

It downloads a file with the name as my_video.mp4 but when I try to open this video it's not playing.

What can be wrong here with my code? OR is there any better way to download the video from URL.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...