【发布时间】:2015-06-25 09:43:23
【问题描述】:
我正在做一个程序来使用 Python 编辑 mp3 上的标签,现在我正在使用 mutagen 模块,为了使用 id3v4 标准将图像作为封面嵌入到 mp3 文件中,我必须添加 APIC 框架@ 987654321@.
但我不明白我必须在参数encoding、mime 和data 中输入什么。
我从这里查看了一个示例并想出了这个:
frame= APIC(3,"image/jpg",3,"Cover",open("albumcover.jpg"))
但我不知道前 3 个是什么意思?为什么当我输入"utf-8" 时它不起作用?而open() 函数不起作用,它返回如下错误:
Traceback (most recent call last):
File "<pyshell#104>", line 1, in <module>
frame= APIC(3,"image/jpg",3,"Cover",open("albumcover.jpg"))
File "C:\Python34\lib\site-packages\mutagen\id3\_frames.py", line 65, in __init__
setattr(self, checker.name, checker.validate(self, val))
File "C:\Python34\lib\site-packages\mutagen\id3\_specs.py", line 184, in validate
raise TypeError("%s has to be bytes" % self.name)
TypeError: data has to be bytes
当我把"b"
frame= APIC(3,"image/jpg",3,"Cover",open("albumcover.jpg","b"))
返回
Traceback (most recent call last):
File "<pyshell#106>", line 1, in <module>
frame= APIC("utf-8","image/jpg",3,"Cover",open("albumcover.jpg","b"))
ValueError: Must have exactly one of create/read/write/append mode and at most one plus
那我应该放什么?
我也尝试了open("albumcover.jpg").read(),但它不起作用。
【问题讨论】:
-
字节问题的答案可能是 [我在 Python 3 中遇到的字符串到字节问题] - stackoverflow.com/questions/5440485/…