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

时间:2017-05-30 20:50:10

标签: django vagrant connection-refused

我确定这是我的错,但我的系统已经工作了好几个月,现在却无法正常工作。我已经查看了Django文档,并在此处查看了stackoverflow,我理解了连接被拒绝的问题'意味着没人在听插座;但我不明白为什么,也不知道如何前进。

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

在我新创建的Vagrant虚拟机上,我安装并配置我的django应用程序并使用' python manage.py runserver运行它们--settings = mumble.settings.py 0.0.0.0:8000&# 39 ;.请注意,这是Django 1.8.3,但同样,它在某些VM上运行良好。

出于神秘的原因,当我创建一个新的流浪汉VM并安装我的django有效载荷(使用尚未更改的部署脚本),并连接到django服务器时,我得到Errno 111 Connection拒绝:

+ 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

有关如何调试的建议吗?

1 个答案:

答案 0 :(得分:1)

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