Forums

OSError: cannot identify image file

UPDATE - Issue fixed - It was an implementation issue that I could fix.


Hello guys!

I have a little function for image resizing that works properly on my local pc. However I get the below error when I run it on PA. I understand that it can't identify the image, but confusing because it works locally. Maybe it's a dependency issue. I would really appreciate if somebody could give me some tips about what should I try. (Pillow is already installed.)

2018-11-22 17:57:56,844: Exception on /upload/horv [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.4/dist-packages/flask/_compat.py", line 33, in reraise
raise value
File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.4/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "...app.py", line 1339, in upload_file
resize_image1(file,output_file_1,320,output_file_kicsi)
File "...app.py", line 1306, in resize_image1
im = Image.open(input_file)
File "/usr/local/lib/python3.4/dist-packages/PIL/Image.py", line 2256, in open
% (filename if filename else fp))
OSError: cannot identify image file <FileStorage: '2018-calendar.jpg' ('image/jpeg')>

I wonder if it's a working directory problem? If you specify a file as '2018-calendar.jpg', then the path with be resolved relative to the working directory that the process running your code has, which might not be what you expect. Are you specifying the file that way (without a directory path)? If so, does specifying it with a full path -- for example, /home/sabinvargas/something/2018-calendar.jpg -- fix the problem?