Adding image is failed when images.tag.save() is called

Issue #95 resolved
Satoshi Hirano
created an issue

Hello,

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'')
    audiofile.tag.save()

Then the following exception has been raised.

Traceback (most recent call last):
  File "C:\Work\Python\eyed3test.py", line 22, in <module>
    main()
  File "C:\Work\Python\eyed3test.py", line 18, in main
    audiofile.tag.save()
  File "C:\Program Files (x86)\Python\lib\site-packages\eyed3\id3\tag.py", line 772, in save
    self._saveV2Tag(version, encoding, max_padding)
  File "C:\Program Files (x86)\Python\lib\site-packages\eyed3\id3\tag.py", line 966, in _saveV2Tag
    max_padding)
  File "C:\Program Files (x86)\Python\lib\site-packages\eyed3\id3\tag.py", line 880, in _render
    raw_frame = f.render()
  File "C:\Program Files (x86)\Python\lib\site-packages\eyed3\id3\frames.py", 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