docker icon indicating copy to clipboard operation
docker copied to clipboard

Images break the API

Open lsalgueiro opened this issue 1 year ago • 6 comments

I'm giving this self-hosting this a whirl. I had some problems with my installation, and so I retraced everything back from a fresh installation to try and pinpoint this, and it seems that downloading the images (with docker compose exec web python3 manage.py download-exercise-images ) functionally breaks the API: PIL throws an exception, which throws a wrench on the whole gear:

nginx-1          | 192.168.1.70 - - [04/Oct/2024:15:52:23 +0000] "GET /api/v2/exercise/search/?language=en,en&term=ches HTTP/1.1" 499 0 "http://192.168.1.20:8080/en/routine/set/1/add" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:130.0) Gecko/20100101 Firefox/130.0" "-"
web-1            | ERROR 2024-10-04 16:52:24,398 log Internal Server Error: /api/v2/exercise/search/
web-1            | Traceback (most recent call last):
web-1            |   File "/usr/local/lib/python3.10/dist-packages/PIL/JpegImagePlugin.py", line 639, in _save
web-1            |     rawmode = RAWMODE[im.mode]
web-1            | KeyError: 'P'
web-1            |
web-1            | The above exception was the direct cause of the following exception:
web-1            |
web-1            | Traceback (most recent call last):
web-1            |   File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/exception.py", line 55, in inner
web-1            |     response = get_response(request)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/base.py", line 197, in _get_response
web-1            |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
web-1            |     return view_func(*args, **kwargs)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/django/views/generic/base.py", line 104, in view
web-1            |     return self.dispatch(request, *args, **kwargs)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/rest_framework/views.py", line 509, in dispatch
web-1            |     response = self.handle_exception(exc)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/rest_framework/views.py", line 469, in handle_exception
web-1            |     self.raise_uncaught_exception(exc)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
web-1            |     raise exc
web-1            |   File "/usr/local/lib/python3.10/dist-packages/rest_framework/views.py", line 506, in dispatch
web-1            |     response = handler(request, *args, **kwargs)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/rest_framework/decorators.py", line 50, in handler
web-1            |     return func(*args, **kwargs)
web-1            |   File "/home/wger/src/wger/exercises/api/views.py", line 378, in search
web-1            |     thumbnail = t.get_thumbnail(aliases.get('micro_cropped')).url
web-1            |   File "/usr/local/lib/python3.10/dist-packages/easy_thumbnails/files.py", line 513, in get_thumbnail
web-1            |     thumbnail = self.generate_thumbnail(
web-1            |   File "/usr/local/lib/python3.10/dist-packages/easy_thumbnails/files.py", line 401, in generate_thumbnail
web-1            |     img = engine.save_pil_image(
web-1            |   File "/usr/local/lib/python3.10/dist-packages/easy_thumbnails/engine.py", line 77, in save_pil_image
web-1            |     image.save(destination, format=format, **options)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/PIL/Image.py", line 2568, in save
web-1            |     save_handler(self, fp, filename)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/PIL/JpegImagePlugin.py", line 642, in _save
web-1            |     raise OSError(msg) from e
web-1            | OSError: cannot write mode P as JPEG
web-1            | ERROR 2024-10-04 16:52:26,808 log Internal Server Error: /api/v2/exercise/search/
web-1            | Traceback (most recent call last):
web-1            |   File "/usr/local/lib/python3.10/dist-packages/PIL/JpegImagePlugin.py", line 639, in _save
web-1            |     rawmode = RAWMODE[im.mode]
web-1            | KeyError: 'P'
web-1            |
web-1            | The above exception was the direct cause of the following exception:
web-1            |
web-1            | Traceback (most recent call last):
web-1            |   File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/exception.py", line 55, in inner
web-1            |     response = get_response(request)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/django/core/handlers/base.py", line 197, in _get_response
web-1            |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
web-1            |     return view_func(*args, **kwargs)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/django/views/generic/base.py", line 104, in view
web-1            |     return self.dispatch(request, *args, **kwargs)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/rest_framework/views.py", line 509, in dispatch
web-1            |     response = self.handle_exception(exc)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/rest_framework/views.py", line 469, in handle_exception
web-1            |     self.raise_uncaught_exception(exc)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
web-1            |     raise exc
web-1            |   File "/usr/local/lib/python3.10/dist-packages/rest_framework/views.py", line 506, in dispatch
web-1            |     response = handler(request, *args, **kwargs)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/rest_framework/decorators.py", line 50, in handler
web-1            |     return func(*args, **kwargs)
web-1            |   File "/home/wger/src/wger/exercises/api/views.py", line 378, in search
web-1            |     thumbnail = t.get_thumbnail(aliases.get('micro_cropped')).url
web-1            |   File "/usr/local/lib/python3.10/dist-packages/easy_thumbnails/files.py", line 513, in get_thumbnail
web-1            |     thumbnail = self.generate_thumbnail(
web-1            |   File "/usr/local/lib/python3.10/dist-packages/easy_thumbnails/files.py", line 401, in generate_thumbnail
web-1            |     img = engine.save_pil_image(
web-1            |   File "/usr/local/lib/python3.10/dist-packages/easy_thumbnails/engine.py", line 77, in save_pil_image
web-1            |     image.save(destination, format=format, **options)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/PIL/Image.py", line 2568, in save
web-1            |     save_handler(self, fp, filename)
web-1            |   File "/usr/local/lib/python3.10/dist-packages/PIL/JpegImagePlugin.py", line 642, in _save
web-1            |     raise OSError(msg) from e
web-1            | OSError: cannot write mode P as JPEG

Thanks in advance for the attention!

lsalgueiro avatar Oct 04 '24 16:10 lsalgueiro