Adding image is failed when is called

Issue #95 resolved
Satoshi Hirano
created an issue


It's first time for me to create a ticket here.

I have been trying to add a image into ID3 tag of mp3 file using eyed3 like following:

import eyed3

def main():
    audiofile = eyed3.load('test.mp3')
    imagedata = open('test.jpg', 'rb').read()
    audiofile.tag.images.set(3, imagedata, u'', u'')

Then the following exception has been raised.

Traceback (most recent call last):
  File "C:\Work\Python\", line 22, in <module>
  File "C:\Work\Python\", line 18, in main
  File "C:\Program Files (x86)\Python\lib\site-packages\eyed3\id3\", line 772, in save
    self._saveV2Tag(version, encoding, max_padding)
  File "C:\Program Files (x86)\Python\lib\site-packages\eyed3\id3\", line 966, in _saveV2Tag
  File "C:\Program Files (x86)\Python\lib\site-packages\eyed3\id3\", line 880, in _render
    raw_frame = f.render()
  File "C:\Program Files (x86)\Python\lib\site-packages\eyed3\id3\", line 613, in render
    data += self.image_data
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

I see several sample code that is same as what I describe here.
I'm not familiar with jpeg format, however jpeg binary has actually 0xff.

Is there anything wrong about my trial?

Comments (5)

  1. Travis Shirk repo owner

    Hi Satoshi,

    The following change in your program will fix it.
    audiofile.tag.images.set(3, imagedata, '', u'')

    The key is to not pass a unicode mimetype, pretty lame I know.. I'll type check for this, thanks for reporting.

  2. Log in to comment