1

I am a completely new user to Python and BuildBot. Currently I am using an e-mail alert when the BuildBot build status changes (moves from success to fail, or vice versa), and failing will e-mail every time there is a failed build. I am encountering the following Python error when sending an email is attempted.

--- <exception caught here> ---
**ESMTPClient.__init__(self, secret, contextFactory, *args, **kw)
exceptions.TypeError?: unbound method init() must be called with ESMTPClient 
instance as first argument (got ESMTPSender instance instead)**

I have found some examples of this error online when searching for an answer, including

You just need to pass 'self' as an argument to 'Thread.init' and calling the super class

but I am still unsure why there is an error. I would appreciate any guidance/help on why this error has occurred and how to go about resolving the issue. I am not the author of this code so I am unsure of what to be looking for to solve the problem.

The email was working before the following code was changed from gmail account to company account.

          c['status'].append(mail.MailNotifier(
                 fromaddr="load.builder@company.co.uk",
                 extraRecipients=["example@company.com",
                      ],
                 sendToInterestedUsers=False,
                 mode=('change', 'failing'),
                 relayhost="smtp.company.lan",
                 useTls=True,
                 smtpUser="lbuilder",
                 smtpPassword="password"))

Here's the block of code producing the exception:

class ESMTPSender(SenderMixin, ESMTPClient): 
    requireAuthentication = True 
    requireTransportSecurity = True 
    def __init__(self, username, secret, contextFactory=None, *args, **kw):  
        self.heloFallback = 0 
        self.username = username 

        if contextFactory is None: 
             contextFactory = self._getContextFactory() 

        ESMTPClient.__init__(self, secret, contextFactory, *args, **kw) 
        self._registerAuthenticators() 

SSA

mgilson
  • 300,191
  • 65
  • 633
  • 696
Sarah92
  • 671
  • 4
  • 12
  • 29
  • Can you post the code where this exception is thrown? – mgilson Jul 16 '12 at 13:39
  • I updated your question with the code that produces the exception (check to make sure I got the indentation correct). As it stands, I don't know why this code would produce that exception as it looks like ESMTPSender inherits from ESMPTClient. – mgilson Jul 16 '12 at 15:00

1 Answers1

1

This seems like it would be a difficult exception to come by -- Generally you don't call __init__ explicitly unless you're inheriting from some other class. Here's one situation where you could get that error:

class Foo(object):
    def __init__(self,*args):
       print("In Foo, args:",args,type(self))

class Bar(object):
    def __init__(self,*args):
        Foo.__init__(self,*args)  #Doesn't work.  Complains that the object isn't the right type.

To fix this, we can make Bar inherit from Foo:

class Bar(Foo):
         #^ Bar now inherits from Foo
    def __init__(self,*args):
        Foo.__init__(self,*args) #This will work now since a Bar instance is a Foo instance

If it doesn't make sense to have Bar subclassed from Foo, you can factor the common code out into a separate function:

def common_code(instance,*args):
    print("Common code: args",args,type(instance))

class Foo(object):
    def __init__(self,*args):
        common_code(self,*args)

class Bar(object):
    def __init__(self,*args):
        common_code(self,*args)

Although this kind of problem can be difficult to diagnose without actually seeing the code which produces the error.

mgilson
  • 300,191
  • 65
  • 633
  • 696
  • Thank you- This is the line which throws the exception:ESMTPClient.__init__(self, secret, contextFactory, *args, **kw) – Sarah92 Jul 16 '12 at 14:20
  • from the function: class ESMTPSender(SenderMixin, ESMTPClient): requireAuthentication = True requireTransportSecurity = True def __init__(self, username, secret, contextFactory=None, *args, **kw): self.heloFallback = 0 self.username = username if contextFactory is None: contextFactory = self._getContextFactory() ESMTPClient.__init__(self, secret, contextFactory, *args, **kw) self._registerAuthenticators() – Sarah92 Jul 16 '12 at 14:23