我正在处理来自该节的信息,其中一个目标是检查是否存在错误并通过电子邮件发送通知。
我能够做的是捕获错误(IqError 或 IqTimeout)并发送一封带有书面信息的通用电子邮件:
except IqTimeout:
USERNAME = 'user'
PASSWORD = 'password'
sender = 'someguy@myemail.com'
receivers = 'bshell@myemail.com'
message = """From: SomeGuy <someguy@myemail.com>
To: Barbara Shell <bshell@myemail.com>
Subject: Alert of an Error
This is a test e-mail message: IqTimeout
"""
smtpObj = smtplib.SMTP('smtp.sendmail.net', 123)
smtpObj.login(USERNAME, PASSWORD)
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
我还尝试使用“错误”节中的信息打印日志,但只有一个字段:
logging.error("Could not register account. Error code: %s" %e.iq['error']['code'])
我想要的是我的节中要发送到电子邮件的错误信息,基本上可以这样处理:
To: bshell@myemail.com
From: someguy@myemail.com
Subject: Alert of an Error
This is your error:
RECV: <iq to="bshell@myemail.net/36457242971338462713453506" from="chat.test.net" id="3" type="error"><oo xmlns="http://chat.net/profile" /><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></iq>
我在用python写。如果您需要更多信息,我将非常愿意回答!
提前致谢!
问候,