栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

“(535, b‘Error: authentication failed‘)“身份验证失败问题

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

“(535, b‘Error: authentication failed‘)“身份验证失败问题

语言:python

一、问题描述:

        在使用python的smtplib模块测试自动发送邮件时,遇到(535, b'Error: authentication failed')报错。代码片段如下:


def mail(message):
    ret = True
    
    current_dt = time.strftime("%Y-%m-%d", time.localtime())
    # current_dt = datetime.strptime(current_dt, '%Y-%m-%d')
    title = current_dt.split(" ")[0] + "程序test"
    msg = MIMEText(message,'plain','utf-8')
    msg['From'] = formataddr(["ai司徒", my_sender])         # 发件人昵称
    msg['To'] = formataddr(["司徒", my_user])               # 接收人昵称
    msg['Subject'] = title                                  # 邮件的主题

    server = smtplib.SMTP_SSL("smtp.163.com", 994)       # 发件人邮箱中的SMTP服务器
    server.login(my_sender, my_pass)  # 发件人邮箱账号、邮箱授权码
    server.sendmail(my_sender, [my_user,], msg.as_string())  
    server.quit()  # 关闭连接

    return ret

二、问题产生原因:

        可能是smtp服务的邮箱身份验证失败,检查登录环节

三、解决方案:

        检查后发现需要使用邮箱的smtp服务授权码而非密码,修改后运行成功。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/355706.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号