简体   繁体   English

Python - 如何以二进制读取模式打开远程文件?

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

I'm trying to use the mutagen module to read the metadata of an mp3 file.我正在尝试使用 mutagen 模块来读取mp3文件的元数据。 The problem is that the module is expecting a local mp3 file, but my mp3 files are on a remote server.问题是该模块需要一个本地mp3文件,但我的mp3文件位于远程服务器上。

This is the line in the module that raises an error when I send a remote mp3 URL as the first parameter.当我发送远程 mp3 URL 作为第一个参数时,这是模块中引发错误的行。

fp = file(f, "rb")

How can I alter this line of code so that it can open a remote file (eg http://remotedomain.com/file.mp3 ) in rb mode ?如何更改这行代码,以便它可以在rb mode打开远程文件(例如http://remotedomain.com/file.mp3 )?

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

binary mode is default二进制模式是默认的

file() can not be used to fetch arbitrary URLs. file() 不能用于获取任意 URL。

See

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM