发送邮件时,报错:AttributeError: 'list' object has no attribute 'encode'
在使用腾讯企业邮箱发送邮件时出现报错:AttributeError: 'list' object has no attribute 'encode'
原因:收件人不能用列表存储数据,需要转为字符串,以逗号分割
解决方法:
将收件人列表转为字符串,以逗号分割
to_list = ['a@xx.com', 'b@xx.com']
msg['to'] = ','.join(to_list)
完整代码:
import smtplib
from email.mime.text import MIMEText
from email.header import Header name = 'xx@xxx.cn'
pwd = 'xxx'
to_list = ['xx@xxx.cn'] content = '<html><head><title>test</title></head><body>这是测试邮件内容</body></html>'
msg = MIMEText(content, 'html', 'utf-8')
msg['form'] = Header('huyang', 'utf-8')
msg['to'] = ','.join(to_list) # 重点是这个位置
msg['subject'] = Header('测试邮件', 'utf-8') #---发送
smtp = smtplib.SMTP_SSL('smtp.exmail.qq.com', 465)
smtp.login(name, pwd)
smtp.sendmail(name, to_list, msg.as_string())
print('发送成功!')
发送邮件时,报错:AttributeError: 'list' object has no attribute 'encode'的更多相关文章
- dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'
有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...
- py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】
问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图 或者 解决方法: 将”driver ...
- 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'
在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...
- Django2.2报错 AttributeError: 'str' object has no attribute 'decode'
准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...
- 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"
最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...
- 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”
报错代码: sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 解决 ...
- python报错“AttributeError: 'set' object has no attribute 'items'“
作为才开始学爬虫的萌新,遇到了一个这样的错,很懵逼 后面到网络到处查看大佬的解决方法,才发现headers的请求头部信息有错误,headers是一个字典,不是字符串,所以报错了 原代码 headers ...
- [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'
原因:openpyxl版本低,需升级 pip install --upgrade openpyxl
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
随机推荐
- 常用 Maven 插件介绍
我们都知道Maven本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给插件来完成,例如编译源代码是由maven- compiler-plugin完成的.进一步说,每个任务对应 ...
- 设置 sudo 无需输入密码
* 设置 sudo 无需输入密码,如下:* [root@localhost ~]# visudo* 在"root ALL=(ALL) ALL"这一行下面,再加入一行:* 将原来的: ...
- Nebula Graph 源码解读系列 | Vol.00 序言
本文首发于 Nebula Graph Community 公众号 Nebula Graph 是由杭州欧若数网科技有限公司(官网:https://www.vesoft.com/cn/)开源的一款分布式图 ...
- [C++逆向] 8 数组和指针的寻址
目录 数组在函数中 字符串 数组作为参数 下标寻址和指针寻址 多维数组 存放指针类型数据的数组 指向数组的指针变量 函数指针 数组是相同类型数据的集合,以先行方式连续储存在内冲中 而指针只是一个保存地 ...
- mySQL清除数据表数据/删除表
一.sql清空表数据的三种方式: 1.truncate – 删除所有数据,保留表结构,不能撤销还原,速度快 2.delete – 是逐行删除,不适合大量数据删除,速度极慢 3.drop – 删除表,表 ...
- Kubernetes CKA考试之Killer Simulator(下)
写在前面 个人微信公众号:密码应用技术实战 个人博客园首页:https://www.cnblogs.com/informatics/ 注:学习交流使用 目录 写在前面 Question 16 | Na ...
- vue2init vue2z
<template> <div> </div> </template> <script> export default { name: 'b ...
- RGB、HSV、HSL和CMYK颜色空间
目录 简介 RGB(红绿蓝)颜色空间 HSV(色调.饱和度.亮度)颜色空间 HSL(色调.饱和度.亮度)颜色空间 CMYK(青.品红.黄.黑)颜色空间 简介 这四种颜色空间在不同的应用领域有不同的用途 ...
- 记录--uni-app实现蓝牙打印小票
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 说明 基于uni-app开发,调用官方蓝牙相关api实现连接蓝牙与向蓝牙热敏打印机发送字节流,可打印文字,二维码,图片,调整字体大小等,本 ...
- 快速上手系列:传智播客Java基础学习笔记
配置环境,把JDK的bin所在路径复制到Path,末尾加; 基本语法 一 常见的DOS命令 盘符的切换 d:回车 目录的进入 cd javase c ...