I'm getting an error message sent to my admin email address:
ADMIN = ['admin.error.email.here@domain.com'] email address.
This error message occurs at a constant rate of around two per minute.
I want to stop all error messages sent to my admin email that are HTTP_HOST errors, but at the same time still receive 500 error messages. I looked at the documentation and couldn't find any help. I searched on Stack Overflow and only found changing nginx 80 port server config file to contain a header error to a 444 error, so to bypass the 500 error report. However, this didn't work.
Is there any setting.py
variable for excluding certain errors? Time is of the essence - like I said, 2 damn emails per minute from some asshole that is desperate to scrape data. It's not a security risk but it is annoying and consuming my monthly email limit from my email host.
Thanks for any help.
First off I didn't test this particular sample yet, but my approach in a similar situation was to write a custom filter for your logging.
For this first write a custom filter:
import logging
class NoAnnoyFilter(logging.Filter):
def filter(self, record):
status_code = getattr(record, 'status_code', None)
return status_code != 500
And then add it to your logging config in your settings.py
:
DEFAULT_LOGGING = {
...
'filters': {
'no_annoy': {
'()': 'myproject.utils.NoAnnoyFilter',
},
},
...
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['no_annoy'],
'class': 'django.utils.log.AdminEmailHandler'
},
...
},
}
You can see some actual samples in the Django code itself: https://github.com/django/django/blob/6709ea4ae91b906742506ac0c42a3a272991001f/django/utils/log.py
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.