简体   繁体   English

我继续收到错误消息“ TypeError:必须为str,而不是字节”

[英]I keep on getting the error “TypeError: must be str, not bytes”

I am not new to python, but I am new to the Tkinter, and smtplib modules. 我对python并不陌生,但是对Tkinter和smtplib模块不熟悉。 I'm trying to set up my own email interface, using tkinter as the GUI, and smtplib to send the emails. 我正在尝试建立自己的电子邮件界面,使用tkinter作为GUI,并通过smtplib发送电子邮件。 The program takes the input from the entry boxes, then uses them to send the emails, but it keeps throwing this error and I don't know how to fix it... 该程序从输入框中获取输入,然后使用它们发送电子邮件,但是它不断抛出此错误,我不知道该如何解决...

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

I have done a bit of research; 我做了一些研究; many people have the same question, but in an entirely different situation (which calls for a different fix). 许多人有相同的问题,但是情况完全不同(需要不同的解决方法)。 So here is my code. 这是我的代码。

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()

After a quick look, I see this line -> user_Password = Two.get missing the brackets on the end of it. 快速浏览后,我看到此行-> user_Password = Two.get缺少结尾的括号。 As a result, the password is probably not being supplied, rather a bytes object which is not the password anyhow. 结果,可能没有提供密码,而是提供了一个字节对象,无论如何,这不是密码。 changing the line to user_Password = Two.get() seems to work for me in my testing 将行更改为user_Password = Two.get()在我的测试中似乎对我user_Password = Two.get()

That should resolve the issue the question asks about although you may possibly end up with a new issue 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') which is beyond the scope of this question. 尽管您可能会遇到新问题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') ,该问题不在此范围内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:必须是str,而不是字节Error - TypeError: must be str, not bytes Error Python sendto错误TypeError:必须为str,而不是字节 - Python sendto Error TypeError: must be str, not bytes TypeError:必须为str,而不是字节 - TypeError: must be str, not bytes 我对字符串和整数有些困惑,并且不断收到此错误:TypeError:列表索引必须是整数或切片,而不是str - I'm a little confused with strings and integers, and I keep getting this error: TypeError: list indices must be integers or slices, not str 我不断收到此错误:列表索引必须是整数或切片,而不是 str - I keep getting this error: list indices must be integers or slices, not str 在 Python3 中解码字节字符串时出错 [TypeError: must be str, not bytes] - Error decoding byte string in Python3 [TypeError: must be str, not bytes] Paperboy 抛出错误:TypeError:JSON 对象必须是 str,而不是“字节”? - Paperboy throwing error: TypeError: the JSON object must be str, not 'bytes'? TypeError:需要一个类似字节的对象,而不是'str':得到此错误 - TypeError: a bytes-like object is required, not 'str' : Getting this error 类型错误:JSON 对象必须是 str,而不是 'bytes' - TypeError: the JSON object must be str, not 'bytes' 编码:TypeError:write()参数必须是str,而不是bytes - Encoding: TypeError: write() argument must be str, not bytes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM