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

拈花ヽ惹草 提交于 2019-12-10 13:27:36

问题


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?


回答1:


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

binary mode is default




回答2:


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

See

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



来源:https://stackoverflow.com/questions/6543737/python-how-to-a-open-remote-file-in-binary-read-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!