Converting HEIC Images to JPEG in python works on local windows but not working in ubuntu aws gunicorn and nginx server

I'm saving heic images to aws s3 bucket and try to convert it to jpeg before displaying it in the html page using python library Pillow and pillow_heif

here is the code for the convertion

import boto3
from PIL import Image
from io import BytesIO
import pillow_heif
response = s3.get_object(Bucket=settings.AWS_STORAGE_BUCKET_NAME,
image_bytes = response['Body'].read()
img =
new_name ='.heic', '.jpg')
# Convert image to JPEG
# Create a BytesIO object to save the image
img_bytes = BytesIO(), format='JPEG')
# Upload the image to S3
s3.upload_fileobj(img_bytes, settings.AWS_STORAGE_BUCKET_NAME, new_name)
self.converted_image_name = new_name
# Get the object URL
url = s3.generate_presigned_url(
             'Bucket': settings.AWS_STORAGE_BUCKET_NAME,
             'Key': new_name
       ExpiresIn=60000 # URL expiration time in seconds

when I run that code in my local machine (Windows) in django using python runserver command it works fine, but when I deploy the code to the aws instance which is running using gunicorn and nginx the url that that code runs in gives 502 Bad Gateway nginx/1.18.0 (Ubuntu) error.

And when I tried to check what is the issue, there is no errors came up in the gunicorn logs and nginx logs also.

Can anyone please help me with this issue?

Back to Top