【问题标题】:Gunicorn wouldn't run Django with WSGIGunicorn 不会使用 WSGI 运行 Django
【发布时间】:2015-10-01 12:05:02
【问题描述】:

我正在尝试使用 gunicorn 运行我的 django 项目,但出现错误。 为了测试,我通过运行以下命令创建了所有新内容:

virtualenv test_gunicorn
source test_gunicorn/bin/activate
pip install django gunicorn
cd test_gunicorn/
mkdir projects
cd projects/
django-admin startproject test_gunicorn
cd test_gunicorn/
gunicorn test_gunicorn/wsgi:application

但仍然遇到与我在原始项目中遇到的完全相同的错误。以下是错误:

[2015-07-13 14:22:33 +0000] [9122] [INFO] Starting gunicorn 19.3.0
[2015-07-13 14:22:33 +0000] [9122] [INFO] Listening at: http://127.0.0.1:8000 (9122)
[2015-07-13 14:22:33 +0000] [9122] [INFO] Using worker: sync
[2015-07-13 14:22:33 +0000] [9127] [INFO] Booting worker with pid: 9127
[2015-07-13 14:22:33 +0000] [9127] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: Import by filename is not supported.
Traceback (most recent call last):
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: Import by filename is not supported.
[2015-07-13 14:22:33 +0000] [9127] [INFO] Worker exiting (pid: 9127)
Traceback (most recent call last):
  File "/home/tahir/official/virtualenvs/test_gunicorn/bin/gunicorn", line 11, in <module>
    sys.exit(run())
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 189, in run
    super(Application, self).run()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 174, in run
    self.manage_workers()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
    self.spawn_workers()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 541, in spawn_workers
    time.sleep(0.1 * random.random())
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 214, in handle_chld
    self.reap_workers()
  File "/home/tahir/official/virtualenvs/test_gunicorn/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

这是pip freeze的输出:

Django==1.8.3
gunicorn==19.3.0

我在这里做错了什么还是 Django 或 gunicorn 有问题?

【问题讨论】:

    标签: python django gunicorn django-wsgi


    【解决方案1】:

    错误是告诉您传递的是文件路径而不是 Python 模块路径。你的 gunicorn 调用应该是:

    gunicorn test_gunicorn.wsgi:application
    

    【讨论】:

      【解决方案2】:

      您应该以 gunicorn test_gunicorn.wsgi:application 开头 gunicorn(注意 test_gunicornwsgi 之间的点而不是斜线)。基本上,语法与您在 Python 中编写 import 语句时的语法相同。

      【讨论】:

        猜你喜欢
        • 2012-09-09
        • 2012-08-17
        • 1970-01-01
        • 1970-01-01
        • 2017-04-11
        • 2012-08-21
        • 2013-03-01
        • 2021-07-08
        • 1970-01-01
        相关资源
        最近更新 更多