Python SMTPLIB , SSL Library Error --> smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted)

Python SMTPLIB , SSL Library Error --> smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted)

我的 python 程序有问题。我在程序中输入了正确的电子邮件和密码信息,错误如下所示

import smtplib, SSL 

email="belginjarosh46@gmail.com"
password="my password"
port = 465

context = ssl.create_default_context()

server =smtplib.SMTP_SSL("smtp.gmail.com",port,context=context) 
server.login(email,password)
message=" Hi I Am Belgin Android "
sender_mail=email,
receiver_email="belginjarosh46@gmail.com"
server.sendmail(sender_mail,receiver_email,message)

错误:

Traceback (most recent call last):
  File "c:/Users/Belgin/Desktop/Python Coding/email_sending.py", line 10, in <module>
    server.login(email,password)
  File "G:\Python\lib\smtplib.py", line 734, in login
    raise last_exception
  File "G:\Python\lib\smtplib.py", line 723, in login
    (code, resp) = self.auth(
  File "G:\Python\lib\smtplib.py", line 646, in auth
    raise SMTPAuthenticationError(code, resp)
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 f21sm2590687pfn.71 - gsmtp')

总结一下 - 我猜问题是 Google 不允许您使用默认用户密码登录,尤其是(但不仅限于)在使用第二因素身份验证时。 因此,对于使用 3rd 方应用程序的密码,它 requires creating app specific passwords