捕获来自 http 的 mp3 流并使用 python 将其保存到磁盘的最佳方法是什么?
到目前为止我已经尝试过
target = open(target_path, "w")
conn = urllib.urlopen(stream_url)
while True:
target.write(conn.read(buf_size))
这给了我数据,但它在 mp3 播放器中出现乱码或无法播放。
最佳答案
如果您使用的是 Windows,您可能会不小心进行 CRLF 转换,从而损坏二进制数据。尝试以二进制模式打开 target
:
target = open(target_path, "wb")
关于python - 如何使用 python 捕获 mp3 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/187552/