I've setup a script to download an mp3 using urllib2 in Python.
url = 'example.com'
req2 = urllib2.Request(url)
response = urllib2.urlopen(req2)
#grab the data
data = response.read()
mp3Name = "song.mp3"
song = open(mp3Name, "w")
song.write(data) # was data2
song.close()
Turns out it was somehow related to me downloading it on Windows or my current Python version. I tested the code on my Ubuntu distro and the mp3 file downloaded perfectly fine... So I just used the simple urllib2.openurl
method and it worked perfect!
To summarize:
- I am using
urllib2.openurl
in Python on an Ubuntu distro. - I am using a newer version of Python but I feel like it can't be that.
- The mp3 are encoded in LAME.
Does anyone have any clue what was causing the weird issue running the code on my Windows box? I wonder why downloading on Windows mangled the mp3?