我正在尝试用Python制作电子邮件客户端。我得到以下错误:
def egonder(self):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
usrnam=self.ad.text()
passwds=self.sifre.text()
if usrnam=="" or passwds=="":
QtGui.QMessageBox.warning("Fill every blank.")
else:
server.login(usrnam,passwds)
self.durum.setText("Logging in...")
mytext=""
self.mesaj.setPlainText(mytext)
msg = self.konu.text(),"\n",mytext
server.sendmail(self.kimden.text(), self.kime.text(), msg)
self.durum.setText("Email sent.")
它给了我以下错误:
File "eposta.py", line 105, in egonder
server.sendmail(self.kimden.text(), self.kime.text(), msg)
File "/usr/lib/python3.4/smtplib.py", line 793, in sendmail
(code, resp) = self.data(msg)
File "/usr/lib/python3.4/smtplib.py", line 532, in data
q = _quote_periods(msg)
File "/usr/lib/python3.4/smtplib.py", line 168, in _quote_periods
return re.sub(br'(?m)^\.', b'..', bindata)
File "/usr/lib/python3.4/re.py", line 175, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or buffer
当我尝试制作消息框时,它会给我错误:
QtGui.QMessageBox.warning("Fill every blank.")
TypeError: arguments did not match any overloaded call:
QMessageBox.warning(QWidget, str, str, QMessageBox.StandardButtons buttons=QMessageBox.Ok, QMessageBox.StandardButton defaultButton=QMessageBox.NoButton): argument 1 has unexpected type 'str'
QMessageBox.warning(QWidget, str, str, int, int, int button2=0): argument 1 has unexpected type 'str'
QMessageBox.warning(QWidget, str, str, str, str button1Text='', str button2Text='', int defaultButtonNumber=0, int escapeButtonNumber=-1): argument 1 has unexpected type 'str'
谢谢
答案 0 :(得分:1)
错误1
您的专栏:msg = self.konu.text(),"\n",mytext
这是创建一个字符串列表。如果你print
,你会看到类似的东西:
('Something', '\n', 'Something More')
SMTP.sendmail需要邮件的字符串。所以试试这个:
msg = "{0}\n{1}".format(self.konu.text(), mytext)
请阅读SMTP.sendmail和string.format
的文档错误2
您没有传递QMessageBox所有必需的参数。至少它需要消息框的父级,标题和消息。所以,如果没有父母:
QtGui.QMessageBox.warning(None, "Invalid input", "Fill every blank.")
请阅读docs