python - TypeError: 'in <string>' requires string as left operand, not QString -
i'm trying write simple app send (and possibly receive) emails gmail account. managed while hardcoding account information in source code, wanted enter them in gui fields , read information there. here code:
import sys import smtplib pyqt4 import qtcore, qtgui notifier_main import ui_notifier_main_gui class maingui(qtgui.qwidget, ui_notifier_main_gui): def __init__(self): qtgui.qwidget.__init__(self) self.setupui(self) self.sendbutton.clicked.connect(self.send) def send(self): fromaddr = self.senderemaillineedit.text() toaddrs = self.receiveremaillineedit.text() msg = self.msgtextedit.toplaintext() username = self.senderemaillineedit.text() server = smtplib.smtp("smtp.gmail.com:587") server.starttls() server.login(username, 'password') server.sendmail(fromaddr, toaddrs, msg) server.quit() if __name__ == "__main__": app = qtgui.qapplication(sys.argv) main_gui = maingui() main_gui.show() sys.exit(app.exec_())
when run long ass error:
c:\python27\python.exe "e:/python projekti/notifier/src/main.py" traceback (most recent call last): file "e:/python projekti/notifier/src/main.py", line 20, in send server.sendmail(fromaddr, toaddrs, msg) file "c:\python27\lib\smtplib.py", line 728, in sendmail (code, resp) = self.mail(from_addr, esmtp_opts) file "c:\python27\lib\smtplib.py", line 480, in mail self.putcmd("mail", "from:%s%s" % (quoteaddr(sender), optionlist)) file "c:\python27\lib\smtplib.py", line 141, in quoteaddr m = email.utils.parseaddr(addr)[1] file "c:\python27\lib\email\utils.py", line 214, in parseaddr addrs = _addresslist(addr).addresslist file "c:\python27\lib\email\_parseaddr.py", line 457, in __init__ self.addresslist = self.getaddrlist() file "c:\python27\lib\email\_parseaddr.py", line 218, in getaddrlist ad = self.getaddress() file "c:\python27\lib\email\_parseaddr.py", line 228, in getaddress self.gotonext() file "c:\python27\lib\email\_parseaddr.py", line 204, in gotonext if self.field[self.pos] in self.lws + '\n\r': typeerror: 'in <string>' requires string left operand, not qstring
i tried googling type error, , found link spyderlib since i'm pretty new @ this, couldn't figure out that.
most requests qt elements have text return qstrings, simple string container qt uses. other libraries going expect regular python strings, casting using str() may necessary. of:
fromaddr = self.senderemaillineedit.text() toaddrs = self.receiveremaillineedit.text() msg = self.msgtextedit.toplaintext() username = self.senderemaillineedit.text()
are qstring objects.
Comments
Post a Comment