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

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Mar 26 08:34:27 EDT 2018


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




More information about the Python-list mailing list