0

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

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

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

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

+ 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

关于如何调试这个的任何建议?

4

1 回答 1

1

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

于 2017-12-01T16:44:44.433 回答