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

后端 未结 1 1437
梦如初夏
梦如初夏 2021-01-18 19:12

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 th         


        
相关标签:
1条回答
  • 2021-01-18 19:43

    Try binary file mode. open(mp3Name, "wb") You're probably getting line ending translations.

    The file is binary, yes. It's the mode that wasn't. When a file is opened, it can be set to read as a text file (this is default). When it does this, it will convert line endings to match the platform. On Windows, line ends are \r\n In most other places it's either \r or \n. This change messes up the data stream.

    0 讨论(0)
提交回复
热议问题