当我从 python 发送电子邮件时,出现错误“浮动”对象没有属性“编码”。这成功运行了 6-7 天,没有任何问题。
def create_message(send_from, send_to, cc_to, subject, plain_text_body):
message = MIMEMultipart('alternative')
message['From'] = send_from
message['To'] =send_to
message['Cc'] = cc_to
message['Date'] = formatdate(localtime=True)
message['Subject'] = subject
message.attach(MIMEText(plain_text_body, 'plain'))
return message
def add_attachment_from_local_disk(message, path):
with open(path, "rb") as file:
part = MIMEApplication(file.read(),Name=basename(path))
part['Content-Disposition'] = 'attachment; filename="%s"' % basename(path)
message.attach(part)
def send_message(message):
print(message)
client = boto3.client("ses",region_name='eu-west-1')
response = client.send_raw_email(RawMessage = {"Data": message.as_string()})
for i, row in final_email.iterrows():
subject = row["Subject"]
to_address = row['fba_to__notifications'] or row['lsp_escalation_back_up'] or "no_address@rs-components.com"
cc_list = row['cc_list']
send_from="ukrd@kuedid.com"
message = create_message(send_from,to_address, cc_list, subject, plain_text_body=body)
send_message(message)
错误
~\AppData\Local\Continuum\anaconda3\lib\email\_policybase.py in _fold(self, name, value, sanitize)
367 if self.max_line_length is not None:
368 maxlinelen = self.max_line_length
--> 369 parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
370 parts.append(self.linesep)
371 return ''.join(parts)
AttributeError: 'float' object has no attribute 'encode'
如何解决这个问题?
四季花海
相关分类