Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchart: Catch PIL file type exception (KeyError) when resizing art #2504

Mycah opened this issue Apr 4, 2017 · 2 comments


None yet
3 participants
Copy link

commented Apr 4, 2017


(Describe your problem, feature request, or discussion topic here. If you're reporting a bug, please fill out this and the "Setup" section below. Otherwise, you can delete them.)

Running this command in verbose (-vv) mode:

$ beet -vv fetchart -f albumartist:"KMFDM" album:"Amnesia"
user configuration: /home/mycah/.config/beets/config.yaml
data directory: /home/mycah/.config/beets
plugin paths:
Sending event: pluginload
inline: adding item field cdtitle
inline: adding item field multidisc
inline: adding item field initial
inline: adding item field nicelength
inline: adding album field cdtype
inline: adding album field notalbum
library database: /home/mmattox/.beets.db
library directory: /home/mmattox/convertedMusic
Sending event: library_opened
fetchart: trying source filesystem for album KMFDM - Amnesia
fetchart: trying source coverart for album KMFDM - Amnesia
ImageMagick check `convert --version` failed: [Errno 2] No such file or directory: 'convert'
artresizer: method is (1, (0,))
fetchart: downloading image:
fetchart: not a supported image: image/x-None
fetchart: downloading image:
fetchart: downloaded art to: /tmp/tmp3i69k972.jpg
fetchart: image size: (700, 700)
fetchart: image needs resizing (700 > 600)
fetchart: using remote image /tmp/tmp3i69k972.jpg
artresizer: PIL resizing /tmp/tmp3i69k972.jpg to /tmp/tmpc9k_0qbc.jpg
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/PIL/", line 1447, in save
    format = EXTENSION[ext]
KeyError: b'.jpg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/PIL/", line 1451, in save
    format = EXTENSION[ext]
KeyError: b'.jpg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/beet", line 9, in <module>
    load_entry_point('beets==1.4.4', 'console_scripts', 'beet')()
  File "/usr/local/lib/python3.4/dist-packages/beets-1.4.4-py3.4.egg/beets/ui/", line 1221, in main
  File "/usr/local/lib/python3.4/dist-packages/beets-1.4.4-py3.4.egg/beets/ui/", line 1208, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/local/lib/python3.4/dist-packages/beets-1.4.4-py3.4.egg/beetsplug/", line 829, in func
    self.batch_fetch_art(lib, lib.albums(ui.decargs(args)), opts.force)
  File "/usr/local/lib/python3.4/dist-packages/beets-1.4.4-py3.4.egg/beetsplug/", line 882, in batch_fetch_art
    candidate = self.art_for_album(album, local_paths)
  File "/usr/local/lib/python3.4/dist-packages/beets-1.4.4-py3.4.egg/beetsplug/", line 865, in art_for_album
  File "/usr/local/lib/python3.4/dist-packages/beets-1.4.4-py3.4.egg/beetsplug/", line 143, in resize
    self.path = ArtResizer.shared.resize(plugin.maxwidth, self.path)
  File "/usr/local/lib/python3.4/dist-packages/beets-1.4.4-py3.4.egg/beets/util/", line 184, in resize
    return func(maxwidth, path_in, path_out)
  File "/usr/local/lib/python3.4/dist-packages/beets-1.4.4-py3.4.egg/beets/util/", line 75, in pil_resize
  File "/usr/lib/python3/dist-packages/PIL/", line 1453, in save
    raise KeyError(ext) # unknown extension
KeyError: b'.jpg'

Led to this problem:

in my config:

    auto: yes
    minwidth: 350
    maxwidth: 600

Here's a link to the music files that trigger the bug (if relevant):


  • OS: ubuntu 14.04
  • Python version: python 3.4.3
  • beets version: 1.4.4
  • Turning off plugins made problem go away (yes/no): plugin issue

My configuration (output of beet config) is:

$ beet config
library: ~/.beets.db

        countries: [US, GB|UK]
        original_year: yes

    "\u2018": ''''
    "\u2019": ''''
    "\u201C": '"'
    "\u201D": '"'
    "\u2010": '-'
    "\u2011": '-'
    "\u2012": '-'
    "\u2013": '-'
    "\u2014": '-'
    "\u2015": '-'
    "\u2016": '-'
    "\u2026": '...'
    cdtitle: u' - %s' % (disctitle) if disctitle else u''
    multidisc: 1 if disctotal > 1 else 0
    initial: artist.lower().lstrip('[]*')[0]
    nicelength: 'm, s = divmod(length, 60)

        h, m = divmod(m, 60)

        return "%d:%02d:%02d" % (h, m, s)


    log: ~/beets.log
    write: yes
    copy: yes
    cdtype: u'[%s]' % (albumtype.lower()) if albumtype else u''
    notalbum: 0 if albumtype and albumtype.lower() == 'album' else 1
            extension: m4a
            command: avconv -i $source -y -vn -acodec alac $dest
        ogg: avconv -i $source -y -vn -acodec libvorbis -aq 3 $dest
        flac: avconv -i $source -y -vn -acodec flac $dest
        wma: avconv -i $source -y -vn -acodec wmav2 -vn $dest
        mp3: avconv -i $source -y -vn -qscale:a 0 $dest
            extension: m4a
            command: avconv -i $source -y -vn -acodec libfaac -aq 100 $dest
        opus: avconv -i $source -y -vn -acodec libopus -ab 96k $dest
    max_bitrate: 500
    embed: yes
    copy_album_art: yes
    threads: 4
    never_convert_lossy_files: no
    pretend: no
    format: mp3
    quiet: no

    paths: {}
    auto: yes
    album_art_maxwidth: 0
pathfields: {}
per_disc_numbering: yes
    include_paths: no
    cors: ''
    port: 8337

    default: albums/$albumartist/%if{$year,$year - }$album%aunique{albumdisambig label catalognum}%if{$multidisc, (disc$disc$cdtitle)}%if{$notalbum, $cdtype}/$track - $title
    comp: albums/000 Various Artists/%if{$year,$year - }$album%aunique{albumdisambig label catalognum}%if{$multidisc, (disc$disc$cdtitle)}%if{$notalbum, $cdtype}/$track - $artist - $title
    singleton: singles/$initial/$artist - $title

- convert
- duplicates
- fromfilename
- fuzzy
- info
- inline
- lastgenre
- mbsync
- random
- scrub
- the
- fetchart
- embedart
asciify_paths: no
directory: ~/convertedMusic
    auto: yes
    maxwidth: 0
    compare_threshold: 0
    ifempty: no
    remove_art_file: no
original_date: yes
    auto: yes
    minwidth: 350
    maxwidth: 600
    store_source: no
    - filesystem
    - coverart
    - itunes
    - amazon
    - albumart
    enforce_ratio: no
    google_key: REDACTED
    - cover
    - front
    - art
    - album
    - folder
    fanarttv_key: REDACTED
    cautious: no
    google_engine: 001442825323518660753:hrh5ch1gjzm
    threshold: 0.7
    prefix: '~'
    source: album
    force: yes
    count: 1
    prefer_specific: no
    min_weight: 10
    canonical: no
    auto: yes
    whitelist: yes
    separator: ', '
    a: yes
    format: '{0}, {1}'
    strip: no
    patterns: []
    the: yes
    auto: yes
    path: no
    copy: ''
    move: ''
    merge: no
    checksum: ''
    strict: no
    tiebreak: {}
    full: no
    delete: no
    count: no
    album: no
    format: ''
    tag: ''
    keys: []

@sampsyo sampsyo added the bug label Apr 4, 2017

@sampsyo sampsyo changed the title Exception: raise KeyError(ext) # unknown extension using pil_resize with python3 fetchart: Catch PIL file type exception (KeyError) when resizing art Apr 4, 2017


This comment has been minimized.

Copy link

commented Apr 4, 2017

Thanks! Looks like PIL behaves poorly when it doesn't have support for JPEG writing. You might try disabling art resizing (or using ImageMagick instead of PIL) for now.


This comment has been minimized.

Copy link

commented Apr 4, 2017

I switched to imagemagick and everything seems fine. Thought I'd add a bug anyhow.


@wisp3rwind wisp3rwind self-assigned this Apr 28, 2017

architek added a commit to architek/beets that referenced this issue Sep 9, 2018

Fixes beetbox#2504
PIL requires a string parameter [1] while under python3 we call it with bytes.
This leads to wrong format detection (b'.png' isn't a key in supported formats list).


sampsyo added a commit that referenced this issue Sep 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.