python smtplib.SMTPAuthenticationError: (535, b'Error: authentication failed')

python smtplib.SMTPAuthenticationError: (535, b’Error: authentication failed’)
出现这个问题:
python smtplib.SMTPAuthenticationError: (535, b'Error: authentication failed')
运行报错:
python smtplib.SMTPAuthenticationError: (535, b'Error: authentication failed')
解决办法使用163邮箱服务器来发送邮件,我们需要去163邮箱开启POP3/SMTP服务,这时163邮件会让我们设置客户端授权码,(参考链接https://jingyan.baidu.com/article/c275f6ba33a95de33d7567d9.html)
设置好授权码拿这个设置的授权码替代上面代码部分的passwd即可成功发送邮件。这里我也不明白为什么是这样替换,有知道的大神希望给一下解释。