Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用哨兵避免曼陀罗错误_Python_Django_Mandrill_Sentry - Fatal编程技术网

Python 用哨兵避免曼陀罗错误

Python 用哨兵避免曼陀罗错误,python,django,mandrill,sentry,Python,Django,Mandrill,Sentry,我已经在我的服务器上安装了一个Sentry实例,我想将其配置为使用及其Django集成发送警报电子邮件。以下是我正在使用的sentry.conf.py文件中的相关设置: EXTRA_INSTALLED_APPS = ( 'djrill', ) EMAIL_BACKEND = 'djrill.mail.backends.djrill.DjrillBackend' MANDRILL_API_KEY = '[... Mandril API key ...]' DEFAULT_FROM_EMA

我已经在我的服务器上安装了一个Sentry实例,我想将其配置为使用及其Django集成发送警报电子邮件。以下是我正在使用的
sentry.conf.py
文件中的相关设置:

EXTRA_INSTALLED_APPS = (
    'djrill',
)
EMAIL_BACKEND = 'djrill.mail.backends.djrill.DjrillBackend'

MANDRILL_API_KEY = '[... Mandril API key ...]'
DEFAULT_FROM_EMAIL = 'my-mandrill-allowed@email.address'
SERVER_EMAIL = 'my-mandrill-allowed@email.address'
除了由于某种原因Mandrill不允许设置
消息Id
标题的部分外,此设置也可以工作:

NotSupportedByMandrillError: Invalid message header 'Message-Id' - Mandrill only allows Reply-To and X-* headers
(此异常由djrill提出,不是Mandrill的响应)

由哨兵设置:

我已经设法通过编辑该方法使其工作,并使其始终返回
None
,因此在电子邮件中未设置
消息Id
标题。但我不喜欢编辑/修补第三方代码,我不知道其他地方是否需要该标题

如何正确地做到这一点?从Mandrill切换现在不是一个选项


谢谢

由于您无法轻松更改Sentry的行为,据我所知,我建议实现
DjrillBackend
的子类,在发送消息之前删除
消息Id
头。类似于(未经测试):


我在安装最新版本的Djrill时解决了这个问题。但我会接受这个答案,因为如果升级不是一个选项,我会实现它。谢谢
class MessageBuilder(object):
    # ...
    @cached_property
    def message_id(self):
        if self.reference is not None:
            return email_id_for_model(self.reference)
class HeaderRemovingBackend(DjrillBackend):
    def send_messages(self, email_messages):
        for message in email_messages:
            if 'Message-Id' in message.extra_headers:
                del message.extra_headers['Message-Id']
        super(HeaderRemovingBackend, self).send_messages(email_messages)