7

Okay. So I am really not happy with that I am probably posting another duplicate question, but nothing relevant seems to help me.

So the problem is that I want to receive emails containing server error messages (500), and I don't.

What do I know:

  1. Everything works just fine on my local machine: I get my messages when I set DEBUG = False. Too many of them, being honest.
  2. Calling django.core.mail.mail_admins() from within ./manage.py shell on production server is working fine: I get my emails, as I get those that are sent by send_email() from within a view
  3. I have DEBUG = False set on my production server
  4. I am trying to get email by messing up my home template with missing parentheses and also by putting assert 0 string into my home view. I am getting my 500.html rendered alright with that.
  5. Here are my email settings in settings.py:

    EMAIL_HOST = 'smtp.yandex.ru'
    EMAIL_HOST_USER = 'noreply@<project-name>.ru'
    EMAIL_HOST_PASSWORD = '<password>'
    EMAIL_PORT = 587
    EMAIL_USE_TLS = True
    DEFAULT_FROM_EMAIL = 'noreply@<project-name>.ru'
    SERVER_EMAIL = 'noreply@<project-name>.ru'
    

  6. Here are my logging settings in settings.py:
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'filters': {
            'require_debug_false': {
                '()': 'django.utils.log.RequireDebugFalse',
            }
        },
        'handlers': {
            'mail_admins': {
                'level': 'ERROR',
                'filters': ['require_debug_false'],
                'class': 'django.utils.log.AdminEmailHandler'
            }
        },
        'loggers': {
            'django': {
                'handlers': ['mail_admins'],
                'level': 'ERROR',
                'propagate': False,
            },
        }
    }
    

    I also tried changing 'propagate' to True, but didn't succeed

  7. And here is my ADMINS from settings.py: ADMINS = (('xelnod', 'xelnod@gmail.com'),)
  8. I am using Django 1.7 with Python 2.7.6
  9. And the production server is running on '57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux'
  10. I was here: https://stackoverflow.com/questions/1414130/,
    and here: https://stackoverflow.com/questions/17374909/,
    and even here: https://stackoverflow.com/questions/19634962/ (so I did run sudo apt-get install sendmail already),
    and in some other places — unfortunately, no luck with that.

…am I missing something (I bet it would be something very stupid…)?

UPD: I noticed that I only receive email messages concerning my static files when I test this on my local — nothing about broken template or AssertionError, so, I guess, it must be something with my error level or my 500 errors are not bad enough for Django to email them… Tried setting handler and logger levels to INFO, but nothing changed

Community
  • 1
  • 1
xelnod
  • 71
  • 6

1 Answers1

0

what's the error message when you have DEBUG = True?

And maybe you need to fix your 500 template, because if that one is broken, you cannot see a 500 error page of a 500 error page

Hussam
  • 488
  • 3
  • 15
  • `AssertionError at / No exception message supplied Request Method: GET Request URL: http://localhost:8082/ Django Version: 1.7c2 Exception Type: AssertionError` That's the one on the home page. – xelnod Jun 23 '15 at 13:10
  • Well, I see my 500.html template, doesn't it mean that there are no errors there? – xelnod Jun 23 '15 at 13:12
  • Are there any templatetags in your 500.html? Try removing them first and just use plain text (nothing else) in this template. Otherwise, post the complete stacktrace for further investigation – Hussam Jun 26 '15 at 09:27
  • Sorry for delay! Tried removing all templatetags - no success. Here's the stacktrace... `AssertionError at / No exception message supplied Request Method: GET Request URL: http://localhost:8082/ Django Version: 1.7 Exception Type: AssertionError Exception Location: /home/ubuntu/repos/tenderon/tenderon/views.py in home, line 164 Python Executable: /venv/tenderon/bin/python Python Version: 2.7.6 Python Path: ['some paths here']` sorry, had to cut out the PYTHONPATH for my comment not to be too long. Can't see anything interesting in the trace, though :( – xelnod Jul 04 '15 at 12:04
  • It does say something about your view `/home/ubuntu/repos/tenderon/tenderon/views.py in home, line 164` maybe you should check that line? – Hussam Jul 09 '15 at 08:37
  • That line just says "assert 0". I deliberately wrote that one in order to get 500 error and receive an email about that since my project usually doesn't throw these... – xelnod Jul 10 '15 at 10:36