gunicorn.errors.HaltServer: HaltServer ‘App failed to load.’ 4

Error executing the following code while installing Gunicorn:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    # return 'hello world'

if __name__ == '__main__':
    app.run(debug=True)

Use the command: Gunicorn WSGI: application-b 0.0.0.0.0:8000-w 2
Error message:

[2019-01-09 15:39:40 +0800] [29565] [INFO] Starting gunicorn 19.9.0
[2019-01-09 15:39:40 +0800] [29565] [INFO] Listening at: http://0.0.0.0:8000 (29565)
[2019-01-09 15:39:40 +0800] [29565] [INFO] Using worker: sync
[2019-01-09 15:39:40 +0800] [29568] [INFO] Booting worker with pid: 29568
[2019-01-09 15:39:40 +0800] [29570] [INFO] Booting worker with pid: 29570
Failed to find application object 'application' in 'wsgi'
[2019-01-09 15:39:40 +0800] [29568] [INFO] Worker exiting (pid: 29568)
Failed to find application object 'application' in 'wsgi'
[2019-01-09 15:39:40 +0800] [29570] [INFO] Worker exiting (pid: 29570)
Traceback (most recent call last):
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/arbiter.py", line 203, in run
    self.manage_workers()
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/arbiter.py", line 545, in manage_workers
    self.spawn_workers()
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/arbiter.py", line 617, in spawn_workers
    time.sleep(0.1 * random.random())
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
    self.reap_workers()
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/arbiter.py", line 528, in reap_workers
    raise HaltServer(reason, self.APP_LOAD_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'App failed to load.' 4>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ejior/.virtualenvs/begin/bin/gunicorn", line 11, in <module>
    sys.exit(run())
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/app/base.py", line 223, in run
    super(Application, self).run()
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/arbiter.py", line 232, in run
    self.halt(reason=inst.reason, exit_status=inst.exit_status)
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/arbiter.py", line 345, in halt
    self.stop()
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
    time.sleep(0.1)
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
    self.reap_workers()
  File "/home/ejior/.virtualenvs/begin/lib/python3.6/site-packages/gunicorn/arbiter.py", line 528, in reap_workers
    raise HaltServer(reason, self.APP_LOAD_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'App failed to load.' 4>

 
Reason for error:
app = Flask(___)). This is defined as app. This should also be used in the command gunicorn-w 4-b 0.0.0.0.0:8000-k gevent wsgi:app.
 
 
 
 

Read More: