Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
元组作为主体的电子邮件列表-Python_Python_List_Email_Tuples - Fatal编程技术网

元组作为主体的电子邮件列表-Python

元组作为主体的电子邮件列表-Python,python,list,email,tuples,Python,List,Email,Tuples,我正在处理一个由服务器(名称、IP)元组组成的列表。我正在使用ping测试每台服务器的连接性。如果ping失败,它将被添加到名为issues的列表中。我正试图通过电子邮件将失败列表发送给我自己,因为有任何失败。我不确定我错了什么,但我得到了以下错误: Traceback (most recent call last): File "C:/Python27/Scripts/serverconnection.py", line 26, in <module> msg['SUB

我正在处理一个由服务器(名称、IP)元组组成的列表。我正在使用ping测试每台服务器的连接性。如果ping失败,它将被添加到名为
issues
的列表中。我正试图通过电子邮件将失败列表发送给我自己,因为有任何失败。我不确定我错了什么,但我得到了以下错误:

Traceback (most recent call last):
  File "C:/Python27/Scripts/serverconnection.py", line 26, in <module>
    msg['SUBJECT'] = "Server Disconnect Notice"
TypeError: 'str' object does not support item assignment

因为msg是一个str,所以你不能像在dict中那样做
msg['SUBJECT']

请尝试以下操作:

msg = dict()
msg['SUBJECT'] = "Server Disconnect Notice"
msg['FROM'] = "Alli Deacon"
msg['TO'] = 'allid@atlanticpkg.com'
msg.send() # i don't know what module for e-mails you use

我需要以下导入:

从email.MIMEText导入MIMEText

然后用以下内容更新了我的代码:

msg = dict()
msg['SUBJECT'] = "Server Disconnect Notice"
msg['FROM'] = "Alli Deacon"
msg['TO'] = 'allid@atlanticpkg.com'
msg.send() # i don't know what module for e-mails you use
msg=MIMEText(正文)


在我使用这些添加内容进行更新后,代码运行良好

谢谢你的帮助,你帮助我意识到我错过了什么。我需要利用MIMEText功能。