Bạn chỉ cần import thêm dòng này là được
from email import encoders
Rảnh quá mình code lại luôn:
import smtplib
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email import encoders
fromaddr = ""
toaddr = ""
msg = MIMEMultipart[]
msg["From"] = fromaddr
msg["To"] = toaddr
msg["Subject"] = "Quang Hihi"
body = "kkkkk"
try:
msg.attach[MIMEText[body, "plain"]]
filename = "/home/pham.huu.quang/PycharmProjects/Text2Speech/data/train_text/label.csv"
attachment = open[filename, "rb"]
part = MIMEBase["application", "octet-stream"]
part.set_payload[attachment.read[]]
encoders.encode_base64[part]
part.add_header["Content-Disposition", "attachment; filename=%s" %filename]
msg.attach[part]
server = smtplib.SMTP["smtp.gmail.com", 587]
server.starttls[]
server.login[fromaddr, "password123"]
text = msg.as_string[]
server.sendmail[fromaddr, toaddr, text]
server.quit[]
except Exception as e:
print[e]
# -*- coding: utf-8 -*-
import math
global a,b,c,d
def f[x]: return a*math.pow[x,3]+b*math.pow[x,2]+c*x+d
def zzz[gha = float[input["> Gioi han A: "]], ghb = float[input["> Gioi han B: "]], saiso=[ghb-gha]/math.pow[2,20]]:
gh=[gha+ghb]/2
if[f[gh]==0 or math.fabs[gha-ghb] < saiso ]: return gh
if f[gha]*f[gh]