如何使用python捕获mp3流

run*_*neh 11 python streaming

捕获来自http的mp3流并使用python将其保存到磁盘的最佳方法是什么?

到目前为止,我已经尝试过

target = open(target_path, "w")
conn = urllib.urlopen(stream_url)
while True:
    target.write(conn.read(buf_size))
Run Code Online (Sandbox Code Playgroud)

这给了我数据,但它的乱码或不会在MP3播放器中播放.

Ada*_*eld 15

如果您使用的是Windows,则可能会意外地进行CRLF转换,从而破坏二进制数据.尝试target以二进制模式打开:

target = open(target_path, "wb")
Run Code Online (Sandbox Code Playgroud)