我对python并不陌生,但是对Tkinter和smtplib模块不熟悉。我正在尝试建立自己的电子邮件界面,使用tkinter作为GUI,并通过smtplib发送电子邮件。该程序从输入框中获取输入,然后使用它们发送电子邮件,但它不断抛出此错误,我不知道该如何解决...
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 1699, in __call__
return self.func(*args)
File "/Users/jonbrain/PycharmProjects/GUI for Email/venv/The
Propper GuI.py", line 39, in send_it
server.login(emailUser, user_Password)
`File"/Library/Frameworks/Python.framework/Versions/3.6/lib/
python3. 6/smtplib.py",
line 721, in login
initial_response_ok=initial_response_ok)
File"/Library/Frameworks/Python.framework/Versions/3.6/lib/
python3.6/smtplib.py", line 631, in auth
(code, resp) = self.docmd("AUTH", mechanism + " " + response)
TypeError: must be str, not bytes
我做了一些研究;许多人有相同的问题,但是情况完全不同(需要不同的解决方法)。这是我的代码。
from tkinter import *
import smtplib
root = Tk()
root.title("Jon's Email Service")
root.geometry("800x400+0+0")
Label(root, text="Jon's Email Service", font=("arial",
60,"bold"), fg="blue").pack()
Label(root, text="User's Email address {Has to be gmail} ",font=
("arial", 20,), fg="black").pack()
One = Entry(root,width=40, bg="white")
One.pack()
Label(root, text="User's Gmail Password", font=("arial",
20,),fg="black").pack()
Two = Entry(root, width=40, bg="white")
Two.pack()
Label(root, text="Email Recipient", font=("arial",
20,),fg="black").pack()
Three = Entry(root,width=40, bg="white")
Three.pack()
Label(root, text="The Message", font=("arial",
20,),fg="black").pack()
Four = Entry(root, width=60, bg="white")
Four.pack()
def send_it():
email_resipient = Three.get()
Label(root, text="Email Is Sent!", font=("arial", 20,),
fg="Red").pack()
emailUser = One.get()
user_Password = Two.get
msg = Four.get()
print(emailUser)
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(emailUser, user_Password)
server.sendmail(emailUser, email_resipient, msg)
server.quit()
send = Button(root, text="Send", default='active', width = 40,
bg = "lightblue",command = send_it).pack()
root.mainloop()
答案 0 :(得分:3)
快速浏览后,我看到此行-> user_Password = Two.get
缺少结尾的括号。结果,可能没有提供密码,而是提供了一个字节对象,无论如何,这不是密码。
在我的测试中,将行更改为user_Password = Two.get()
似乎很适合我
这应该可以解决问题所要解决的问题,尽管您可能最终会遇到新问题smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials 196sm197509481pfc.77 - gsmtp')
,但此问题不在此范围内。