Getting "LazyImporter' object is not callable" error when trying to send email using python smtplib

Sum sjsumitj at gmail.com
Mon Mar 26 12:18:21 EDT 2018


Thanks Steve for your inputs.
Now I am able to run the code successfully.

# Made changes to import statements as below:
        from email.mime.base import MIMEBase
        from email.mime.text import MIMEText


Apologies for the typo and indentation error in above mail.

Regards,
Sumit


On Mon, Mar 26, 2018 at 6:04 PM, Steven D'Aprano <
steve+comp.lang.python at pearwood.info> wrote:

> On Mon, 26 Mar 2018 16:47:26 +0530, Sum wrote:
>
> > Hi,
> >
> > Getting "LazyImporter' object is not callable" error. I have enabled
> > allow less secure app setting in sender gmail.
> >
> > Code :
>
> The code you show is not the same as the code you are actually running.
> The error message you give says:
>
> File "test_mail.py", line 64, in
>   send_email(to, SUBJECT, TEXT, attachment_file)
> File "test_mail.py", line 24, in send_email
>   msg.attach(MIMEText(text))
> TypeError: 'LazyImporter' object is not callable
>
>
> Notice the quoted line 24. Here it is again:
>
>     msg.attach(MIMEText(text))
>
> But line 24 in the code you give us is:
>
>     msg.attach(part)
>
>
> which is different. Also, you have a line of code:
>
>     except smtplib.SMTPException,error::
>
> Notice the two colons at the end of the line? That's a syntax error. So
> the code you have shown us cannot possibly be the same as the code you
> are running.
>
> Please review your code, copy and paste the complete traceback, starting
> with the line "Traceback", and make sure that you have run the code you
> show us.
>
> It might help to read this page:
>
> http://sscce.org/
>
> It's written for Java programmers, but the ideas apply equally to Python.
>
>
> Thank you,
>
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list