简体   繁体   中英

Django error: [Errno 60] Operation timed out

I know the title is a little ambiguous and I'd only ever ask here if it wasn't a last resort - but I am stuck. I've pulled down a Django project from my work repo that is rather ancient (we're talking 1.13), and I've been tasked with bringing it into 1.9. Okay, fair enough.

I've loaded the database from a MySQL dump and faked the migrations just fine. However, when I run the server, I get hit with this:

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 316, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 291, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
    raise err
error: [Errno 60] Operation timed out

At first, I had no idea what was going on here, but from the look of it, SMTP is throwing this exception - probably due to the mailing server not being accessible. Any how, I can't even get print statements to show up in settings.py , and so have no idea where to even start to trace this problem through.

Any guidance would be lovely.

EDIT: Here is the new error:

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 177, in __call__
    response = self.get_response(request)
  File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/handlers/base.py", line 230, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/handlers/base.py", line 284, in handle_uncaught_exception
    'request': request
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1191, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1284, in _log
    self.handle(record)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1294, in handle
    self.callHandlers(record)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 1334, in callHandlers
    hdlr.handle(record)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 757, in handle
    self.emit(record)
  File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/utils/log.py", line 117, in emit
    self.send_mail(subject, message, fail_silently=True, html_message=html_message)
  File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/utils/log.py", line 120, in send_mail
    mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
  File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/mail/__init__.py", line 97, in mail_admins
    mail.send(fail_silently=fail_silently)
  File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/mail/message.py", line 292, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
    new_conn_created = self.open()
  File "/Users/krisvukasinovic/.virtualenvs/give2gether/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 58, in open
    self.connection = connection_class(self.host, self.port, **connection_params)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 316, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 291, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
    raise err
error: [Errno 61] Connection refused

As you know, the error you were getting is because your logger was set up to send emails whenever you received an error. The problem being that your development environment doesn't have access to the mail server that this logger relies on.

What happens is django then raises this new error and the actual error gets hidden away.

The actual solution to this is to create a separate settings.py file for development, that way you don't need to worry about the mail server not being there, nor (I expect) would you really care.

When running runserver you can then specify this settings file with

 runserver --settings=mysettings

For completeness, heres a very simple development settings.py file

from myapp.settings import *

print 'DEV'
DEBUG = True
# INSTALLED_APPS += ['debug_toolbar']
# MIDDLEWARE_CLASSES += ['debug_toolbar.middleware.DebugToolbarMiddleware']

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM