Django + Vagrant VM突然说Errno 111:连接拒绝

问题描述:

我敢肯定这是我的错,但是我的系统已经工作了好几个月,现在不管用了。我看过Django文档和这里的计算器,并且我理解'连接被拒绝'意味着没有人在套接字上侦听;但我不明白为什么,也不知道如何前进。Django + Vagrant VM突然说Errno 111:连接拒绝

我在MacPro上使用Vagrant + VirtualBox,六个月后,我已经能够创建虚拟机并运行我的应用程序,没有任何问题。我有一些虚拟机的一切正常工作。

在我新创建的Vagrant VM上,我安装并配置了我的django应用程序,并使用'python manage.py runserver --settings = mumble.settings.py 0.0.0.0:8000'来运行它们。请注意,这是Django 1.8.3,但它仍然适用于某些虚拟机。

对于神秘的原因,当我创建一个新的游民VM并安装我的Django的有效载荷(使用部署并没有改变脚本),并连接到服务器的Django,我得到errno的111连接被拒绝:

+ python ./manage.py runserver --settings=mydjango.settings 0.0.0.0:8000 
       ..... 
      _d^^^^^^^^^b_ 
     .d''   ``b. 
    .p'    `q. 
    .d'     `b. 
    .d'      `b. * Mezzanine 4.0.1 
    ::      :: * Django 1.8.3 
    :: M E Z Z A N I N E :: * Python 2.7.12 
    ::      :: * MySQL 5.7.18 
    `p.      .q' * Linux 4.4.0-75-generic 
    `p.     .q' 
    `b.     .d' 
     `q..   ..p' 
      ^q........p^ 
       '''' 

Performing system checks... 

System check identified no issues (0 silenced). 
May 31, 2017 - 09:50:50 
Django version 1.8.3, using settings 'mydjango.settings' 
Starting development server at http://0.0.0.0: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 "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 189, in __call__ 
    response = self.get_response(request) 
    File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 204, in get_response 
    'request': request 
    File "/usr/lib/python2.7/logging/__init__.py", line 1185, in error 
    Log 'msg % args' with severity 'ERROR'. 
    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 "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/utils/log.py", line 129, in emit 
    self.send_mail(subject, message, fail_silently=True, html_message=html_message) 
    File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/utils/log.py", line 132, in send_mail 
    mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs) 
    File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 98, in mail_admins 
    mail.send(fail_silently=fail_silently) 
    File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send 
    return self.get_connection(fail_silently).send_messages([self]) 
    File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages 
    new_conn_created = self.open() 
    File "/vagrant/repos_here/www.mydjango.org/venv/www/local/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 "/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 111] Connection refused 
[31/May/2017 09:50:55]"GET /donate/ HTTP/1.1" 500 59 

事情我知道:

这里是一个奇怪的事情:我放下了Django教程,使用'runserver'命令,它的工作!

[vagrant][~/tmp/django_tutorial/mysite] 
$ python manage.py runserver 0.0.0.0:8000 
Performing system checks... 

System check identified no issues (0 silenced). 
May 30, 2017 - 20:36:44 
Django version 1.8.3, using settings 'mysite.settings' 
Starting development server at http://0.0.0.0:8000/ 
Quit the server with CONTROL-C. 
[30/May/2017 20:37:05]"GET/HTTP/1.1" 200 1767 

关于如何调试的建议?

+0

失败时是否有完整的堆栈跟踪?它似乎在smtplib.py失败,所以它似乎尝试发送电子邮件?完整的跟踪可能有助于追踪发生的原因。 – Oliver

+0

你的应用程序正在做一些邮件的事情 - 我不知道你如何配置邮件服务器(本地主机?),但你需要检查邮件服务器的属性,并确保你可以访问 - 如果它的本地主机,检查“telnet localhost 25”只是为了看看你是否在那里倾听 –

答案与我的环境无关。我的同事为settings.ADMINS添加了一个名称,在此之前它已经是一个空列表。当ADMINS是非空列表时,任何错误都会触发尝试向ADMINS中的所有电子邮件地址发送电子邮件,并且我的虚拟机未配置为发送电子邮件。这是记录,但没有强调。这个问题没有发生在我的同事身上,因为相关的更改没有触发服务器错误。