Pythonでsmtplibを使用してExcelファイルを添付したメールを送信しようとしています。次のようなエラーが発生します。 TypeError: 'str' object is not callable
これが私のコードです:
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)
なぜこれが機能しないのですか?
編集:これがエラーの原因のようですfile(absolute_file_location).read()
....。私はそれを別の行に置くことによってこれを決定しました。