开发者

Python - how to a open remote file in binary read mode?

开发者 https://www.devze.com 2023-03-16 11:29 出处:网络
I\'m trying to use the mutagen module to read the metadata of an mp3 file. The problem is that the module is expecting a local mp3 file, but my mp3 files are on a remote server.

I'm trying to use the mutagen module to read the metadata of an mp3 file. The problem is that the module is expecting a local mp3 file, but my mp3 files are on a remote server.

This is 开发者_运维问答the line in the module that raises an error when I send a remote mp3 URL as the first parameter.

fp = file(f, "rb")

How can I alter this line of code so that it can open a remote file (e.g. http://remotedomain.com/file.mp3) in rb mode?


fp = urllib2.urlopen("http://remotedomain.com/file.mp3")

binary mode is default


file() can not be used to fetch arbitrary URLs.

See

http://docs.python.org/dev/howto/urllib2.html

0

精彩评论

暂无评论...
验证码 换一张
取 消