Opened 9 years ago

Last modified 4 years ago

#5318 accepted defect

cannot write mode P as JPEG

Reported by: ayleph Owned by:
Priority: minor Milestone:
Component: programming Keywords: error, image, jpeg, rgb
Cc: Parent Tickets:


A user tried to upload an image which produced the following error. A stackoverflow thread mentions converting to RGB space.

(mediagoblin-0.8.0) ~/mediagoblin $ bin/gmg reprocess run 4028 initial
DEBUG:mediagoblin.processing.task:Processing <MediaEntry 4028: otters>
ERROR:mediagoblin.processing.task:An unhandled exception was raised while processing <MediaEntry 4028: otters>
WARNING:mediagoblin.processing:No idea what happened here, but it failed: IOError('cannot write mode P as JPEG',)
WARNING:mediagoblin.processing:No idea what happened here, but it failed: IOError('cannot write mode P as JPEG',)
Traceback (most recent call last):
  File "bin/gmg", line 9, in <module>
    load_entry_point('mediagoblin==0.8.1.dev0', 'console_scripts', 'gmg')()
  File "/path/to/mediagoblin/mediagoblin/gmg_commands/", line 142, in main_cli
  File "/path/to/mediagoblin/mediagoblin/gmg_commands/", line 293, in reprocess
  File "/path/to/mediagoblin/mediagoblin/gmg_commands/", line 205, in run
  File "/path/to/mediagoblin/mediagoblin/submit/", line 257, in run_process_media
  File "/path/to/mediagoblin/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/app/", line 547, in apply_async
    link=link, link_error=link_error, **options)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/app/", line 739, in apply
    request=request, propagate=throw)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/app/", line 355, in eager_trace_task
    uuid, args, kwargs, request)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/app/", line 253, in trace_task
    I, R, state, retval = on_error(task_request, exc, uuid)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/app/", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/path/to/mediagoblin/mediagoblin/processing/", line 101, in run
  File "/path/to/mediagoblin/mediagoblin/media_types/image/", line 318, in process
    self.generate_thumb(size=thumb_size, filter=filter, quality=quality)
  File "/path/to/mediagoblin/mediagoblin/media_types/image/", line 221, in generate_thumb
    filter, size)
  File "/path/to/mediagoblin/mediagoblin/media_types/image/", line 125, in resize_tool
    quality, filter)
  File "/path/to/mediagoblin/mediagoblin/media_types/image/", line 81, in resize_image, quality=quality)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/PIL/", line 1682, in save
    save_handler(self, fp, filename)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/PIL/", line 571, in _save
    raise IOError("cannot write mode %s as JPEG" % im.mode)
IOError: cannot write mode P as JPEG

Change History (6)

comment:1 by ayleph, 9 years ago

Priority: majorminor

Changing priority as I only saw this issue once.

comment:2 by Loic Dachary, 8 years ago

Unless steps to reproduce the problem are added to this issue, it should probably be closed.

comment:3 by Ben Sturmfels, 8 years ago

Resolution: worksforme
Status: newclosed

I've spent some time trying to reproduce this issue, but no luck. I've tried various images including one with Adobe RGB colour space (as opposed to the more common sRGB).

I was able to make processing fail with a 1200x900 indexed PNG file (ie. one that needed resizing), but it didn't fail as above, so I'll create a separate ticket. Error was "OSError: cannot identify image file", re-raised as a BadMediaFail exception.

As Loic suggests, I'll close this as we can't reproduce it at this stage. Would love to hear if anyone comes up with an example that triggers this.

comment:4 by ayleph, 8 years ago

Okay with me. If I run across this again, I'll grab the image that causes it and share that in the ticket.

comment:5 by ayleph, 6 years ago

Resolution: worksforme
Status: closedaccepted

This just happened again. In this case it's a .gif that was named .gif.jpg prior to being uploaded.

Edit: the file was too large to attach to trac, so you can find it at the link below instead.

Last edited 6 years ago by ayleph (previous) (diff)

comment:6 by Ben Sturmfels, 4 years ago

This is related to #5444. I'm starting to wonder whether filename should be used at all and whether it would be more robust to rely completely on sniffing.

Note: See TracTickets for help on using tickets.