Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress admin email on django ALLOWED_HOSTS exception

Tags:

Since the introduction of the ALLOWED_HOSTS setting in django 1.4.4, I get a lot of django error emails to my admin address for exceptions caused by some silly spider looking for vulnerable phpMyAdmin installations or somesuch. These mails are totally valid since the host headers in the spiders' requests are indeed wrong, but I'd rather have django only send me error mails when important things go wrong. Is there a simple method to silence SuspiciousOperation mails, or do I have to go all the way and subclass CommonMiddleware?

like image 706
Simon Avatar asked Mar 13 '13 11:03

Simon


1 Answers

For completeness you can override parts of the logging: (tested on django 1.6):

LOGGING = {     'version': 1,     'disable_existing_loggers': False,     'handlers': {         'null': {             'level': 'DEBUG',             'class': 'logging.NullHandler',         },     },     'loggers': {         'django.security.DisallowedHost': {             'handlers': ['null'],             'propagate': False,         },     }, } 

Also see Django security docs.

like image 142
Daniel Backman Avatar answered Oct 17 '22 02:10

Daniel Backman