First time here? Check out the FAQ!

AttributeError: SMTP instance has no attribute 'sock'

After some minutes starting the server (tried with gunicorn, uwsgi, mod_wsgi) I get this error. Why does it work normally but stop working after some time?

Traceback (most recent call last):
  File "/home/wiseguy/projects/venv/local/lib/python2.7/site-packages/gunicorn/workers/", line 131, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/wiseguy/projects/venv/local/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/handlers/", line 255, in __call__
    response = self.get_response(request)
  File "/home/wiseguy/projects/venv/local/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/handlers/", line 178, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/home/wiseguy/projects/venv/local/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/handlers/", line 212, in handle_uncaught_exception
    'request': request
  File "/usr/lib/python2.7/logging/", line 1166, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/lib/python2.7/logging/", line 1258, in _log
  File "/usr/lib/python2.7/logging/", line 1268, in handle
  File "/usr/lib/python2.7/logging/", line 1308, in callHandlers
  File "/usr/lib/python2.7/logging/", line 748, in handle
  File "/home/wiseguy/projects/venv/local/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/utils/", line 113, in emit
    mail.mail_admins(subject, message, fail_silently=True, html_message=html_message)
  File "/home/wiseguy/projects/venv/local/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/mail/", line 98, in mail_admins
  File "/home/wiseguy/projects/venv/local/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/mail/", line 255, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/wiseguy/projects/venv/local/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/mail/backends/", line 99, in send_messages
  File "/home/wiseguy/projects/venv/local/lib/python2.7/site-packages/Django-1.5-py2.7.egg/django/core/mail/backends/", line 72, in close
  File "/usr/lib/python2.7/", line 747, in close
    if self.sock:
AttributeError: SMTP instance has no attribute 'sock'
odyssey's avatar
asked 2013-12-05 17:06:27 -0600
edit flag offensive 0 remove flag close merge delete


add a comment see more comments

2 Answers


I have just come across and solved a problem that was throwing this same traceback. The error was indeed unrelated to SMTP. You see that email-related error for the simple fact that django is trying to log the exception via its default logging configuration which includes sending an email to the admins of the site.

To help me in debugging my problem, I set DEBUG=True in settings and I then got the real problem reported: a couple of missing settings.

AJJ's avatar
answered 2014-06-07 03:35:30 -0600, updated 2014-06-07 03:36:41 -0600
edit flag offensive 0 remove flag delete link


add a comment see more comments

I've seen this error a few times and usually its because of an import error somewhere. Based on my experience is unlikely the error has and thing to do with SMTP. I also saw this when my database was misconfigred have you made any code or configuration changes recently?

JStarcher's avatar
answered 2013-12-09 23:51:10 -0600
edit flag offensive 0 remove flag delete link


nope, there seems to be some other concealed exceptions. How one deals with those mysterious errors I am yet to find out.. For example following the advice on skin creation at wiki I made a skin folder copying templates and stuff. Now when I update the email of a user for example via admin interface i get jinja2.exceptions.UndefinedError: 'skin' is undefined I wonder if this has anything to do with skins

odyssey's avatar odyssey (2013-12-10 01:10:30 -0600) edit
add a comment see more comments