这是settings.py
root@00d72ee95c2d:/var/www/eve-auth# cat settings.py
DOMAIN = {'people': {}}
这是run.py
from eve import Eve
app = Eve()
if __name__ == '__main__':
app.run()
当我独立运行时,它可以工作:
root@00d72ee95c2d:/var/www/eve-auth# python run.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
但是当我通过gunicorn启动它时无法运行:
root@00d72ee95c2d:/var/www/eve-auth# gunicorn -b 0.0.0.0:5000 run:app
[2016-02-12 02:07:22 +0000] [20] [INFO] Starting gunicorn 19.4.5
[2016-02-12 02:07:22 +0000] [20] [INFO] Listening at: http://0.0.0.0:5000 (20)
[2016-02-12 02:07:22 +0000] [20] [INFO] Using worker: sync
[2016-02-12 02:07:22 +0000] [23] [INFO] Booting worker with pid: 23
[2016-02-12 02:07:22 +0000] [23] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 246, in validate_domain_struct
domain = self.config['DOMAIN']
KeyError: 'DOMAIN'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 122, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.5/site-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
File "/var/www/eve-auth/run.py", line 2, in <module>
app = Eve()
File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 135, in __init__
self.validate_domain_struct()
File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 248, in validate_domain_struct
raise ConfigException('DOMAIN dictionary missing or wrong.')
eve.exceptions.ConfigException: DOMAIN dictionary missing or wrong.
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 246, in validate_domain_struct
domain = self.config['DOMAIN']
KeyError: 'DOMAIN'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 122, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.5/site-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
File "/var/www/eve-auth/run.py", line 2, in <module>
app = Eve()
File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 135, in __init__
self.validate_domain_struct()
File "/usr/local/lib/python3.5/site-packages/eve/flaskapp.py", line 248, in validate_domain_struct
raise ConfigException('DOMAIN dictionary missing or wrong.')
eve.exceptions.ConfigException: DOMAIN dictionary missing or wrong.
[2016-02-12 02:07:22 +0000] [23] [INFO] Worker exiting (pid: 23)
[2016-02-12 02:07:22 +0000] [20] [INFO] Shutting down: Master
[2016-02-12 02:07:22 +0000] [20] [INFO] Reason: Worker failed to boot.
我找不到任何关于gunicorn和python-eve的文档…所以我不确定从哪里挖掘.
解决方法:
我从未在Gunicorn上过夏娃.然而,Eve是Flask的一个子类,大多数与Flask一起工作的东西也适用于Eve.
根据Flask documentation你在Gunicorn上运行Flask / Eve是这样的:
gunicorn myproject:app
希望这可以帮助.