ssl.SSLEOFError:EOF违反协议(_ssl.c:590)

时间:2016-04-15 07:48:49

标签: python ssl gmail

我通过gmail发送一些预定的电子邮件,在Windows上使用python 2.7。几天前,我开始收到此错误,没有对作业,python安装或Windows服务器进行任何更改。

这是当天发送的第一封电子邮件。后续电子邮件通过就好了。在早上从命令行手动运行时,它运行得很好。

任何关于可能出错的想法,或者如何解决/解决它的想法都会受到赞赏。

来自'mymethodsfile'的方法看起来像这样

import sys
import ast
from datetime import datetime

import smtplib
import mimetypes
from email.mime.multipart import MIMEMultipart
from email import encoders
from email.message import Message
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.text import MIMEText


    def send(self):
        msg = MIMEMultipart('alternative')
        msg['From']=self.sender
        msg['Subject']=self.subject
        msg['To'] = ", ".join(self.recipients) # to must be array of the form ['mailsender135@gmail.com']
        #msg.preamble = "preamble goes here"
        #check if there are attachments if yes, add them
        if self.attachments:
            self.attach(msg)
        #add html body after attachments
        msg.attach(MIMEText(self.htmlbody, 'html'))
        #send
        s = smtplib.SMTP('smtp.gmail.com:587')
        s.starttls()
        s.login(self.sender,self.senderpass)
        s.sendmail(self.sender, self.recipients, msg.as_string())
        s.quit()

日志错误(匿名的脚本路径和文件名):

Traceback (most recent call last):
  File "C:\path\filename.py", line 12, in <module>
    mymail.send()
  File "C:\path2\mymethodsfile.py", line 49, in send
    s.starttls()
  File "C:\Python27\lib\smtplib.py", line 649, in starttls
    self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)
  File "C:\Python27\lib\ssl.py", line 911, in wrap_socket
    ciphers=ciphers)
  File "C:\Python27\lib\ssl.py", line 579, in __init__
    self.do_handshake()
  File "C:\Python27\lib\ssl.py", line 808, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:590)

0 个答案:

没有答案