I’m trying to send an email with an excel file attached using smtplib in python. I’m getting an error saying: TypeError: 'str' object is not callable
Here is my code:
email_message = email.MIMEMultipart.MIMEMultipart('mixed')
excel_attach = email.mime.base.MIMEBase('application','vnd.ms-excel')
# Gives error "TypeError: 'str' object is not callable"
excel_attach.set_payload(file(absolute_file_location).read())
email.encoders.encode_base64(excel_attach)
excel_attach.add_header('Content-Disposition','attachment;filename={0}'.format(file))
email_message.attach(excel_attach)
Why isn’t this working?
EDIT: This appears to be the source of error…. file(absolute_file_location).read(). I’ve determined this by putting it on a different line.
There was a problem with
file(absolute_file_location).read()I don’t know what the problem was, but getting the contents by doing something like…
worked as intended.