Search code examples
pythontwistedbuildbotmailnotifier

Buildbot MailNotifier Error


I am trying to set up a simple email notification system for every build using Buildbot's reporter.MailNotifier. I have implemented it on two Windows computers, and one linux machine and replicated the same error. Here is the code snippet

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 protected]', sendToInterestedUsers=False,
                            relayhost="smtp.gmail.com",smtpPort=587, useTls=True,
                            extraRecipients=["[email protected]"],
                            smtpUser="[email protected]", smtpPassword="email_password")
c['services'] = [mn]

However, every time I receive the following error in 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()

Quick info: Error appears on both Buildbot 0.9.8 and 0.9.1 on Windows 10 (64-bit) and Ubuntu 14.04. The error log is from Python 2.7.13 virtualenv 15.1.0 twisted 17.5.0. Inserting the following code in _parseaddr.py works but I'm looking for a better fix.

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

Solution

  • It was a typo in the recent release of Twisted 17.5.0

    Around line 1900 of twisted/mail/smtp.py in the constructor of class SMTPSenderFactory:

    toEmailFinal.append(email)
    

    should have been

    toEmailFinal.append(_email)
    

    The former passed the entire email module instead of passing just the parsed email, which produced the error. The newer releases will probably fix that or you can manually replace the line in the file. The fix (by rodrigc) can be found in this GitHub commit