あなたの middleware.py には、次のものが必要です。
if asbool(full_stack):
# Handle Python exceptions
app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
# Display error documents for 401, 403, 404 status codes (and
# 500 when debug is disabled)
if asbool(config['debug']):
app = StatusCodeRedirect(app)
else:
app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
エラーを処理します。ただし、エラーが発生したときに電子メールを送信する場合は、エラーの詳細を電子メールに送信するコードのクリティカル セクションで呼び出すヘルパー関数を記述するか、このミドルウェア (ErrorHandler) を書き直すことができます。
ofc 既存の ErrorHandler にそのヘルパー関数呼び出しを追加することもできますが、お勧めしません (既存の lib を変更するのは良いプログラミングではありません)。
そのヘルパー関数のコード:
import turbomail
def send_mail(body, author,subject, to):
conf = {
'mail.on': True,
'mail.transport': 'smtp',
'mail.smtp.server': 'smtp.DOMAIN.SMT:25',
}
turbomail.interface.start(conf)
message = turbomail.Message(
author = author,
to = to,
subject = subject,
plain = body,
encoding = "utf-8"
)
message.send()
turbomail.interface.stop()
それが役に立てば幸い...