Buildbot MailNotifier错误

时间:2017-06-16 04:39:15

标签: python twisted buildbot mailnotifier

我正在尝试使用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')]

1 个答案:

答案 0 :(得分:3)

最近发布的Twisted 17.5.0是一个错字

在SMTPSenderFactory类的构造函数中,在twisted / mail / smtp.py的第1900行附近:

toEmailFinal.append(email)

应该是

toEmailFinal.append(_email)

前者传递了整个电子邮件模块,而不是只传递解析后的电子邮件,这会产生错误。较新的版本可能会解决这个问题,或者您可以手动替换文件中的行。可以在此rodrigc

中找到此修复程序(GitHub commit