我是Python和BuildBot的全新用户。目前,当BuildBot构建状态更改时,我使用的是电子邮件警报(从成功移动到失败,反之亦然),每次生成失败时,失败都会发送电子邮件。尝试发送电子邮件时,我遇到下面的Python错误。
--- <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)**我在网上搜索答案时发现了一些这个错误的例子,包括
您只需将'self‘作为参数传递给'Thread.init’,并调用超类
但我仍然不知道为什么会有错误。我希望能就这个错误发生的原因和如何解决这个问题提供任何指导/帮助。我不是这个代码的作者,所以我不知道要找什么来解决这个问题。
在以下代码从gmail帐户更改为公司帐户之前,电子邮件正在工作。
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"))下面是生成异常的代码块:
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
发布于 2012-07-16 13:56:38
这似乎是一个困难的例外--通常,除非从其他类继承,否则不会显式调用__init__。这里有一种情况,您可以得到这个错误:
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.要解决这个问题,我们可以让Bar从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如果让Bar从Foo中子类没有意义,您可以将公共代码分解到一个单独的函数中:
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)虽然这类问题很难诊断,但如果不实际看到产生错误的代码,就很难诊断。
https://stackoverflow.com/questions/11505558
复制相似问题