Django - Errors not showing on page, connection timeout error thrown after a while
<p>I'm having this issue that suddenly appeared with no obvious reasons. Initially, the errors and exceptions were being displayed both on the page and the console. However, whenever I get or reproduce any kind of error and refresh the page to see the results, the page loads for too long and nothing appear in the python server console. After few minutes, I get this error on the page <code>A server error occurred.  Please contact the administrator</code>. </p>

<p>And this in the console: </p>

<pre><code>Django version 1.7.1, using settings 'snb_mail.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/home/hamza/envsite/local/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__
    return self.application(environ, start_response)
  File "/home/hamza/envsite/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    response = self.get_response(request)
  File "/home/hamza/envsite/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/home/hamza/envsite/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 231, in handle_uncaught_exception
    'request': request
  File "/usr/lib/python2.7/logging/__init__.py", line 1193, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/lib/python2.7/logging/__init__.py", line 1286, in _log
    self.handle(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 1296, in handle
    self.callHandlers(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 1336, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 759, in handle
    self.emit(record)
  File "/home/hamza/envsite/local/lib/python2.7/site-packages/django/utils/log.py", line 132, in emit
    connection=self.connection())
  File "/home/hamza/envsite/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 98, in mail_admins
    mail.send(fail_silently=fail_silently)
  File "/home/hamza/envsite/local/lib/python2.7/site-packages/django/core/mail/message.py", line 286, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/hamza/envsite/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 92, in send_messages
    new_conn_created = self.open()
  File "/home/hamza/envsite/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 50, in open
    self.connection = connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 316, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "/usr/lib/python2.7/socket.py", line 575, in create_connection
    raise err
error: [Errno 110] Connection timed out
[14/Oct/2016 06:36:44] "GET /collections/recommended-for-you/ HTTP/1.1" 500 59
</code></pre>

<p>I haven't done any modification on the settings.py file or the database. This issue only started happening when I opened a page containing a very large set of unpaginated data. Since then, no Syntax error / typeerror or anything appear. The page just keep loading and until the error(s) above appear.</p>

<p>Here is my view.py code: </p>

<pre><code>@csrf_exempt
def store(request, url_name):
    blablabla*&amp;21cv34&amp;* # To force syntax error

    try:
        store = item_inspired.models.ItemInspired.objects.get(url=url_name)
    except:
        response = render_to_response('404.html', {'user': request.the_user})
        return response

    response = render_to_response('store.html', {
        'user': request.the_user,
        'store': store
        })
    return response
</code></pre>

<p>I discovered the source of the issue, which turned out to be from settings.py file. This piece of code was causing the breakage. Once removed, I was able to view the errors:</p>

<pre><code>LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s',
            #'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': 'log/log_file_sh_v3_mail.log',
            'formatter': 'verbose'
        },
        'console': {
            'level': 'INFO',
            'filters': ['require_debug_false'],
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            #'filters': ['special']
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file', 'mail_admins'],
            'propagate': True,
            #'level':'DEBUG',
        },
        'django.request': {
            'handlers': ['file', 'mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
        'myproject.custom': {
            'handlers': ['file', 'console', 'mail_admins'],
            'level': 'INFO',
            #'filters': ['special']
        }
    }
}
</code></pre>

python django