Error while trying to open file with finders "Located outside of base path.."

Viewed 31

I am trying to attach an image to an email, but Finders is not finding it. I tried changing path, moving image, creating a new folder.. nothing seems to work. For some reason, the base path is showing the .virtualenv path, while I have It worked on my local server, but as soon as I put it on a staging server (online), I get this error in console when trying to send email:

django.core.exceptions.SuspiciousFileOperation: The joined path (/home/ubuntu/project/static/images/email_imgs/fld-logo.png) is located outside of the base path component (/home/ubuntu/.virtualenv/lib/python3.5/site-packages/django/contrib/admin/static)

Here is my .py to send an email:

  message = EmailMultiAlternatives(
         subject="**Test Email",
          body=html_message,
           from_email="direct@project.com.au",
                to=email_to_list,
                *args
            )
            message.mixed_subtype = 'related'
            message.attach_alternative(html_message, "text/html")
            message.attach(image_data("fld-logo.png"))



def image_data(image):
    with open(finders.find(settings.MEDIA_ROOT+'/images/email_imgs/'+image), 'rb') as f:
        logo_data = f.read()
    logo = MIMEImage(logo_data)
    logo.add_header('Content-ID', '<image>')
    return logo  
0 Answers
Related