Buildbot MailNotifier 错误

Buildbot MailNotifier Error

我正在尝试使用 Buildbot reporter.MailNotifier 为每个构建设置一个简单的电子邮件通知系统。我已经在两台 Windows 计算机和一台 linux 计算机上实现了它并复制了相同的错误。这是代码片段

from buildbot.plugins import *

c = BuildmasterConfig = {}
#Added workers, protocols, and other configurations

#Test scheduler
c['schedulers'] = [schedulers.Periodic(name="tester", builderNames=["runtest"], periodicBuildTimer=60)]

####### BUILDBOT SERVICES
mn = reporters.MailNotifier(fromaddr='email@gmail.com', sendToInterestedUsers=False,
                            relayhost="smtp.gmail.com",smtpPort=587, useTls=True,
                            extraRecipients=["email@gmail.com"],
                            smtpUser="email@gmail.com", smtpPassword="email_password")
c['services'] = [mn]

但是,每次我在 twistd.log 中收到以下错误:

2017-06-15 21:20:14-0700 [ESMTPSender,client] SMTP Client retrying server. Retry: 1
2017-06-15 21:20:15-0700 [ESMTPSender,client] Unhandled Error
    Traceback (most recent call last):
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\python\log.py", line 103, in callWithLogger
        return callWithContext({"system": lp}, func, *args, **kw)
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\python\log.py", line 86, in callWithContext
        return context.call({ILogContext: newCtx}, func, *args, **kw)
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\python\context.py", line 122, in callWithContext
        return self.currentContext().callWithContext(ctx, func, *args, **kw)
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\python\context.py", line 85, in callWithContext
        return func(*args,**kw)
    --- <exception caught here> ---
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\internet\selectreactor.py", line 149, in _doReadOrWrite
        why = getattr(selectable, method)()
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\internet\tcp.py", line 208, in doRead
        return self._dataReceived(data)
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\internet\tcp.py", line 214, in _dataReceived
        rval = self.protocol.dataReceived(data)
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\protocols\tls.py", line 330, in dataReceived
        self._flushReceiveBIO()
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\protocols\tls.py", line 295, in _flushReceiveBIO
        ProtocolWrapper.dataReceived(self, bytes)
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\protocols\policies.py", line 120, in dataReceived
        self.wrappedProtocol.dataReceived(data)
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\protocols\basic.py", line 571, in dataReceived
        why = self.lineReceived(line)
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\mail\smtp.py", line 995, in lineReceived
        why = self._okresponse(self.code, b'\n'.join(self.resp))
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\mail\smtp.py", line 1044, in smtpState_to
        return self.smtpState_toOrData(0, b'')
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\mail\smtp.py", line 1062, in smtpState_toOrData
        self.sendLine(b'RCPT TO:' + quoteaddr(self.lastAddress))
      File "c:\users\me\buildbot\sandbox\lib\site-packages\twisted\mail\smtp.py", line 179, in quoteaddr
        res = email.utils.parseaddr(addr)
      File "c:\python27\Lib\email\utils.py", line 214, in parseaddr
        addrs = _AddressList(addr).addresslist
      File "c:\python27\Lib\email\_parseaddr.py", line 457, in __init__
        self.addresslist = self.getaddrlist()
      File "c:\python27\Lib\email\_parseaddr.py", line 217, in getaddrlist
        while self.pos < len(self.field):
    exceptions.TypeError: object of type 'module' has no len()

快速信息:Windows 10(64 位)和 Ubuntu 14.04 上的 Buildbot 0.9.8 和 0.9.1 均出现错误。错误日志来自Python 2.7.13 virtualenv 15.1.0 twisted 17.5.0。在 _parseaddr.py 中插入以下代码有效,但我正在寻找更好的修复方法。

if str(type(self.field)) == "<type 'module'>":
    return [('',u'email@gmail.com')]

这是最近发布的 Twisted 17.5.0 中的错字

在 class SMTPSenderFactory:

的构造函数中 twisted/mail/smtp.py 的第 1900 行附近
toEmailFinal.append(email)

应该是

toEmailFinal.append(_email)

前者传递了整个电子邮件模块,而不是仅传递了已解析的电子邮件,从而产生了错误。较新的版本可能会修复该问题,或者您可以手动替换文件中的行。修复(通过 rodrigc) can be found in this GitHub commit