第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從 python 發(fā)送電子郵件時(shí)獲取“浮動(dòng)”對(duì)象沒有屬性“編碼”

從 python 發(fā)送電子郵件時(shí)獲取“浮動(dòng)”對(duì)象沒有屬性“編碼”

弒天下 2023-03-22 17:07:22
當(dāng)我從 python 發(fā)送電子郵件時(shí),出現(xiàn)錯(cuò)誤“浮動(dòng)”對(duì)象沒有屬性“編碼”。這成功運(yùn)行了 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 messagedef 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)錯(cuò)誤~\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'如何解決這個(gè)問題?
查看完整描述

1 回答

?
四季花海

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊

該錯(cuò)誤表明庫(kù)在需要字符串的地方收到了一個(gè)浮點(diǎn)數(shù)。從您的代碼中,我希望其中一個(gè)body或一個(gè)字段final_email包含一個(gè)浮點(diǎn)數(shù)。


由于數(shù)據(jù)框中的空值,浮點(diǎn)數(shù)是 NaN 我不會(huì)感到驚訝。為了確保(或使您的代碼更健壯),您可以嘗試過(guò)濾異常并顯示有問題的值:


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"

    try:

        message = create_message(send_from,to_address, cc_list, subject, plain_text_body=body)

    except AttributeError as e:

        print('Error composing email', send_from,to_address, cc_list, subject, body, '\n', e)

        # raise # optionaly re-raise the exception if you want to stop processing

    send_message(message)

無(wú)論如何,這里還有另一個(gè)問題。NaN被視為True在 Python 代碼中轉(zhuǎn)換為布爾值時(shí)。因此,如果它是 NaN,to_address賦值將不會(huì)回退到表達(dá)式。or因此,您應(yīng)該combine_first在有意義的情況下選擇相關(guān)列 ( final_email['fba_to__notifications'].combine_first(final_email['lsp_escalation_back_up'].fillna('no_address@rs-components.com')),或者明確測(cè)試 NaN 值:


to_address = row['fba_to__notifications'] if not np.isnan(row['fba_to__notifications']) \

    else row['lsp_escalation_back_up'] if not isnan(row['lsp_escalation_back_up']) \

    else "no_address@rs-components.com"


查看完整回答
反對(duì) 回復(fù) 2023-03-22
  • 1 回答
  • 0 關(guān)注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)