httpwebrequest - Downloading Mp3 using Python in Windows mangles the song however in Linux it doesn't -


i've setup script download mp3 using urllib2 in python.

url = 'example.com' req2 = urllib2.request(url) response = urllib2.urlopen(req2)  #grab data data = response.read()  mp3name = "song.mp3" song = open(mp3name, "w") song.write(data)    # data2 song.close() 

turns out somehow related me downloading on windows or current python version. tested code on ubuntu distro , mp3 file downloaded fine... used simple urllib2.openurl method , worked perfect!

to summarize:

  • i using urllib2.openurl in python on ubuntu distro.
  • i using newer version of python feel can't that.
  • the mp3 encoded in lame.

does have clue causing weird issue running code on windows box? wonder why downloading on windows mangled mp3?

try binary file mode. open(mp3name, "wb") you're getting line ending translations.

the file binary, yes. it's mode wasn't. when file opened, can set read text file (this default). when this, convert line endings match platform. on windows, line ends \r\n in other places it's either \r or \n. change messes data stream.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -