Shivam Mitra Shivam Mitra -4 years ago 216
Python Question

Downloading a song through python-requests

I was trying to make a script to download songs from internet. I was first trying to download the song by using "requests" library. But I was unable to play the song. Then, I did the same using "urllib2" library and I was able to play the song this time.

Can't we use "requests" library to download songs? If yes, how?

Code by using requests:

import requests
doc = requests.get("")
f = open("movie.mp3","wb")

Code by using urllib2:

import urllib2
mp3file = urllib2.urlopen("")
output = open('test.mp3','wb')

Answer Source

Use doc.content to save binary data:

import requests

doc = requests.get('')
with open('movie.mp3', 'wb') as f:
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download