• Register
1 vote
1.2k views

Problem :

I am very new to Django. I have recently installed the Django app and now I am trying to set it up with the Gunicorn first and soon after with the Supervisor and Nginx. My Django app is running with a normal Django command as expected for example python manage.py runserver. I have already  installed my Gunicorn using the pip for example pip install gunicorn and my Django version is 1.5.3. But when I try to run a below command and it is inside a virtual env as shown below

gunicorn hello.wsgi:application -b xx.xxx.xxx.xx:8000

And getting the below error

Traceback (most recent call last):
  File "/root/Envs/proj/bin/gunicorn", line 9, in <module>
    load_entry_point('gunicorn==19.0.0', 'console_scripts', 'gunicorn')()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 166, in run
    super(Application, self).run()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
    Arbiter(self).run()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run
    self.manage_workers()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
    self.spawn_workers()
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 537, in spawn_workers
    time.sleep(0.1 * random.random())
  File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
    self.reap_workers()
  File "/root/Envs/proj/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>

Can some expert help me in fixing above error?

9 6 2
3,980 points

Please log in or register to answer this question.

2 Answers

1 vote

Solution :

I have gone through your problem and I can assure that I have the quick fix for your issue. Your problem here is related to wsgi file itself in the past before the Django 1.3 a wsgi file was named with an extension of .wsgi, but now in the recent versions it will be created with and the extension of your .py that is a wsgi file must be the python module. So your file must be hello_wsgi.py and so your command should be as shown below:

gunicorn  hello:application -b xx.xxx.xxx.xx:8000
I hope you will be able to save your time in fixing your problem with the help of my above solution.
5 4 2
17,150 points
0 votes

Solution:

really the problem here was the wsgi file itself, formerly before django 1.3 the wsgi file was named with an extension of .wsgi, however now in the current versions it will be created with and extension of .py that is the wsgi file should be a python module

so the file must be hello_wsgi.py and command must be

gunicorn  hello:application -b xx.xxx.xxx.xx:8000

run guncorn with --preload can view the error log, like this

gunicorn app:application --preload -b 0.0.0.0:5000 

This will generally give you a more detailed error message.

You don't displayed a full output. It's possibly looks like

$ gunicorn elcarweb.wsgi
[2015-10-27 21:01:47 +0000] [5429] [INFO] Starting gunicorn 19.2.1
[2015-10-27 21:01:47 +0000] [5429] [INFO] Listening at: http://127.0.0.1:8000 (5429)
[2015-10-27 21:01:47 +0000] [5429] [INFO] Using worker: sync
[2015-10-27 21:01:47 +0000] [5434] [INFO] Booting worker with pid: 5434
[2015-10-27 21:01:47 +0000] [5434] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 503, in spawn_worker
    worker.init_process()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 116, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: No module named elcarweb.wsgi
Traceback (most recent call last):
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 503, in spawn_worker
    worker.init_process()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 116, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: No module named elcarweb.wsgi
[2015-10-27 21:01:47 +0000] [5434] [INFO] Worker exiting (pid: 5434)
Traceback (most recent call last):
  File "/home/tomek/Elcar/elcarweb/env/bin/gunicorn", line 11, in <module>
    sys.exit(run())
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 189, in run
    super(Application, self).run()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 170, in run
    self.manage_workers()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in manage_workers
    self.spawn_workers()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 537, in spawn_workers
    time.sleep(0.1 * random.random())
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 210, in handle_chld
    self.reap_workers()
  File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 455, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

 However before You view necessary informations:

ImportError: No module named elcarweb.wsgi

In case You view this error, then resolution is run gunicorn with --chdir=/your/app/dir parameter.

I also had a same error in Ubuntu 16.04, Django 1.11, employing systemd.

My issue was that I had split my settings out into separate files; for example: instead of having all settings in project/settings.py, I have a some settings files like project/settings/dev.py.

I had to update DJANGO_SETTINGS_MODULE in the project/wsgi.py file from:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")  

to

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings.dev")

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 14 views
14 views
Problem: I am unable to understand this problem .. Please suggest me a better solution to solve it ..bash: gunicorn: command not found
asked Apr 20 Ifra 34.7k points
1 vote
1 answer 18 views
18 views
Problem : How to solve this > Exception Type: PicklingError at / Exception Value: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
asked Apr 22 Abik Dey 4k points
0 votes
1 answer 21 views
21 views
Problem: Please help me out: how to solve error : failed building wheel for mysql-python.
asked Mar 19 Wafa Abu Yousef 6.1k points
0 votes
2 answers 416 views
416 views
I want to run a Django application in PyCharm which works on MySQL DB. I am unable to connect my program to the database. When I am trying to install MySQLclient or MySQL-python I am getting the error: Failed building wheel for MySQLclient Please help me out in connecting my Django program with MySQL database.
asked Oct 24, 2020 psandprop 2.4k points
0 votes
1 answer 4 views
4 views
Problem: How to ? Search the server logs for possible server side errors .
asked Mar 20 PkGuy 23.5k points
0 votes
1 answer 165 views
165 views
Problem: no python application found, check your startup logs for errors.
asked Feb 21 charles mathews 5.5k points
0 votes
1 answer 7 views
7 views
Problem: How can you solve a 502 error?I believe whats causing the 502 error is a nested loop that contains heavy calculations. It would take up to 2 minutes for it to finish that block of code on my local server. However on a public server I just get this 502 Bad Gateway nginx/1.10.3 (Ubuntu).
asked Apr 26 sumaiya simi 43.9k points
0 votes
1 answer 1.1K views
1.1K views
Problem : My Environment is Nginx + uwsgi and I am very new to it. I am getting a 502 bad gateway error from Nginx on certain GET requests. It seems to be related to a length of URL.. Please find below the nginx/error.log [error] 22113#0: *1 recv ... response header from upstream, client: 192.168.1.100, server: server.domain.com, request: "GET <long_url_here>" Can somebody solve this issue?
asked Nov 27, 2019 alecxe 7.5k points
0 votes
1 answer 1 view
1 view
Problem: The current path, account/login/, didn't match any of these?What is the problem here?. The redirect works, I have a feeling its in urlpatterns but cannot for the life figure it out. Driving me crazy today. Thanks for the help and sorry for the essay!
asked 2 days ago sumaiya simi 43.9k points
0 votes
1 answer 3 views
3 views
Problem: I am currently trying out Django. I use the namespace argument in one of my include()s in urls.py. When I run the server and try to browse, I get this error. File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\conf.py", ... ?P<wine_id>[0-9]+)/$', views.wine_detail, name='wine_detail'), ] What do I pass the app_name as stated in the error message?
asked 3 days ago anika11 32k points