Problems configuring deployment with Heroku/gunicorn/django - django

I'm trying to run my django application on heroku.
Folder structure:
app/
Procfile
docs/
...
project/
manage.py
wsgi.py
<django apps>
Procfile
web: gunicorn --pythonpath="$PWD/project" wsgi:application --log-file=-
Error I'm getting:
2015-02-16T16:05:00.646316+00:00 heroku[web.1]: Starting process with command `gunicorn --pythonpath="$PWD/project" wsgi:application --log-file=-`
2015-02-16T16:05:02.697633+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Listening at: http://0.0.0.0:44846 (3)
2015-02-16T16:05:02.709567+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [9] [INFO] Booting worker with pid: 9
2015-02-16T16:05:02.696968+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Starting gunicorn 19.1.1
2015-02-16T16:05:02.697790+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Using worker: sync
2015-02-16T16:05:02.793753+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [10] [INFO] Booting worker with pid: 10
2015-02-16T16:05:03.157305+00:00 app[web.1]: Traceback (most recent call last):
2015-02-16T16:05:03.157311+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2015-02-16T16:05:03.157351+00:00 app[web.1]: sys.exit(run())
2015-02-16T16:05:03.157383+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2015-02-16T16:05:03.157461+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2015-02-16T16:05:03.157463+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
2015-02-16T16:05:03.157506+00:00 app[web.1]: super(Application, self).run()
2015-02-16T16:05:03.157527+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
2015-02-16T16:05:03.157604+00:00 app[web.1]: Arbiter(self).run()
2015-02-16T16:05:03.157607+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 196, in run
2015-02-16T16:05:03.157635+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2015-02-16T16:05:03.157656+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 292, in halt
2015-02-16T16:05:03.157730+00:00 app[web.1]: self.stop()
2015-02-16T16:05:03.157744+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 343, in stop
2015-02-16T16:05:03.157814+00:00 app[web.1]: time.sleep(0.1)
2015-02-16T16:05:03.157836+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
2015-02-16T16:05:03.157887+00:00 app[web.1]: self.reap_workers()
2015-02-16T16:05:03.157908+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
2015-02-16T16:05:03.158009+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2015-02-16T16:05:03.158075+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2015-02-16T16:05:03.904714+00:00 heroku[web.1]: Process exited with status 1
2015-02-16T16:05:03.914410+00:00 heroku[web.1]: State changed from starting to crashed
Update 1
My wsgi.py file
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config")
os.environ.setdefault("DJANGO_CONFIGURATION", "Production")
from configurations.wsgi import get_wsgi_application
application = get_wsgi_application()
Here I am just adding some text because SO has this silly minimum amount of text that must be written in a question. I mean, I do get it that quality needs to be kept, but if the problem is self explanatory why force people to write unneeded text? Thanks and have a great day!

Adding --preload to the gunicorn command in the Procfile will make your Traceback a lot more readable and show you the actual errors.
Exmaple:
gunicorn project.wsgi:application --preload --workers 1

I had a similar problem, after reading he docs for gunicorn, I was able to add
--log-level debug
to the
web: gunicorn project.wsgi:application --log-file -
such that its
web: gunicorn project.wsgi:application --log-file - --log-level debug
In my case the path was also an issue.

Finally found the solution, it was a missing dependency of django-organizations. I find it crazy that there is no way (at least not that I could find) to see any useful error output from heroku. I finally did
heroku run bash --app <app_name>
and then ran the wsgi.py file line by line, finally getting some meaningful error on
from configurations.wsgi import get_wsgi_application # noqa
It was then clear that it's a missing module error, installed it and everything runs perfectly fine.

Change your Procfile to:
web: gunicorn project.wsgi:application --log-file=-
You're missing the project module in the python path to the wsgi.py file.

I solved it. I followed these steps:
Remove all the unused libraries.
Delete requirements.txt file.
Create a new requirements.txt file.
Commit to Git and then deploy on Heroku.

Related

nginx with gunicorn and django on centos 7

I'm trying to make my nginx and gunicorn start working... but seemingly trying everything I could do, fails...
If I do:
systemctl restart nginx
systemctl status nginx
It shows green, and it works...
If I do:
systemctl start gunicorn.socket
systemctl status gunicorn.socket -l
It shows green and works fine...
But if I do:
systemctl start gunicorn.service
systemctl status gunicorn.service -l
it shows me the following message:
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2020-09-10 14:17:23 UTC; 15min ago
Process: 22145 ExecStart=/home/scorg/pro/sc_project/bin/gunicorn --workers 3 --bind unix:/home/scorg/pro/projects/sc/sc.sock sc.wsgi:application (code=exited, status=3)
Main PID: 22145 (code=exited, status=3)
Sep 10 14:17:23 gunicorn[22145]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Sep 10 14:17:23 gunicorn[22145]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Sep 10 14:17:23 gunicorn[22145]: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Sep 10 14:17:23 : ModuleNotFoundError: No module named 'sc'
Sep 10 14:17:23 : [2020-09-10 14:17:23 +0000] [22152] [INFO] Worker exiting (pid: 22152)
Sep 10 14:17:23 : [2020-09-10 14:17:23 +0000] [22145] [INFO] Shutting down: Master
Sep 10 14:17:23 : [2020-09-10 14:17:23 +0000] [22145] [INFO] Reason: Worker failed to boot.
Sep 10 14:17:23 : gunicorn.service: main process exited, code=exited, status=3/NOTIMPLEMENTED
Sep 10 14:17:23 : Unit gunicorn.service entered failed state.
Sep 10 14:17:23 : gunicorn.service failed.
I kind of understand it is bind problem and I followed this question:
Gunicorn, no module named 'myproject
But whatever module I try to bind with the following command, it just doesn't work:
gunicorn --bind 0.0.0.0:8000 wsgi:application
I tried wsgi, sc.wsgi, sc/wsgi, /whole_path/wsgi It's just always the same result... mofule not found...
my gunicorn.service looks like this:
#!/bin/sh
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=root
#scorg
Group=root
#www-data
Environment=SECRET_KEY=secret
WorkingDirectory=/home/scorg/pro/projects/sc/sc
ExecStart=/home/scorg/pro/sc_project/bin/gunicorn --workers 3 --bind unix:/home/scorg/pro/projects/sc/sc.sock sc.wsgi:application
[Install]
WantedBy=multi-user.target
The structure is as following:
sc
├── manage.py
├── sc
│ ├── asgi.py
│ ├── __init__.py
│ ├── __pycache__
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── sc_site
├── admin.py
├── apps.py
├── forms.py
├── models.py
├── __pycache__
├── static
│ ├── admin
│ ├── css
│
├── templates
├── urls.py
└── views.py
I'm in the world of pain at the time. I was struggling with Apache ... I'm noob at centos 7/ linux servers management... Apparently I am stuck... If I forgot to give some extra information... Please let me know, I will happily make an update...
Also I did make sure that I set up gunicorn... So it is on the system and works...:
yum install python-gunicorn
Update
After all fight with the options for gunicorn, it is using python 2.7. I have python 3.8.5... I tried to follow this tutorial How to get Gunicorn to use Python 3 instead of Python 2 (502 Bad Gateway) , but so far I cannot figure out completely what to do... I did everything and it's still using python2.7... Interesting thing:
I tried to delete gunicorn... pip uninstall guncorn
And system tells me that I don't have gunicorn, same story with pip3...
I installed gunicorn with pip3 install gunicorn, but it still trying to use python2.7:
[[/home/scorg/pro]]# sc_project/bin/gunicorn_start
Starting scorg_app as root
DJANGO_SETTINGS_MODULE
PYTHONPATH
2020-09-14 11:15:43 [4865] [INFO] Starting gunicorn 18.0
2020-09-14 11:15:43 [4865] [DEBUG] Arbiter booted
2020-09-14 11:15:43 [4865] [INFO] Listening at: unix:/home/scorg/pro/run/gunicorn.sock (4865)
2020-09-14 11:15:43 [4865] [INFO] Using worker: sync
2020-09-14 11:15:43 [4871] [INFO] Booting worker with pid: 4871
2020-09-14 11:15:43 [4871] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.sc.sc.wsgi
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.scrap.scrap.wsgi
2020-09-14 11:15:43 [4871] [INFO] Worker exiting (pid: 4871)
2020-09-14 11:15:43 [4872] [INFO] Booting worker with pid: 4872
2020-09-14 11:15:43 [4872] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.sc.sc.wsgi
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.sc.sc.wsgi
2020-09-14 11:15:43 [4872] [INFO] Worker exiting (pid: 4872)
2020-09-14 11:15:43 [4873] [INFO] Booting worker with pid: 4873
2020-09-14 11:15:43 [4873] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.scrap.scrap.wsgi
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.sc.sc.wsgi
2020-09-14 11:15:43 [4873] [INFO] Worker exiting (pid: 4873)
Traceback (most recent call last):
File "/bin/gunicorn", line 9, in <module>
load_entry_point('gunicorn==18.0', 'console_scripts', 'gunicorn')()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 71, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 143, in run
Arbiter(self).run()
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 203,in run
self.halt(reason=inst.reason, exit_status=inst.exit_status)
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 298,in halt
self.stop()
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 341,in stop
self.reap_workers()
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 452,in reap_workers
raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
But when I try uninstall gunicorn, it tried to uninstall gunicorn for python3.8... While I'm trying to run gunicorn it runs for python2.7... Unbelievable...
[ [/home/scorg/pro]]# pip uninstall gunicorn
Found existing installation: gunicorn 20.0.4
Uninstalling gunicorn-20.0.4:
Would remove:
/usr/local/bin/gunicorn
/usr/local/lib/python3.8/site-packages/gunicorn-20.0.4.dist-info/*
/usr/local/lib/python3.8/site-packages/gunicorn/*
Proceed (y/n)? y
Successfully uninstalled gunicorn-20.0.4
If you have virtualenv follow this steps:
create guncorn.conf config file
ex: touch /opt/yourproject/gunicorn.conf
import multiprocessing
workers = multiprocessing.cpu_count()*2+1
bind='unix:/var/run/gunicorn.sock'
logfile="/var/log/guni.log"
errorlog = '-'
loglevel = 'info'
accesslog = '-'
timeout=120
proc_name = "yourproject"
user="root"
group="root"
create "gunicorn_start" file.
ex: touch /opt/yourproject/gunicorn_start
#!/bin/bash
NAME="yourproject"
DJANGODIR= **** #ex: /home/yourproject/ #change this
ENVBIN=/yourvirtualenvdir/bin/
SOCKFILE=/var/run/gunicorn.sock
USER=root
GROUP=root
NUM_WORKERS=5 #change this
DJANGO_SETTINGS_MODULE= **** #ex: yourproject.settigns.main #change this
DJANGO_WSGI_MODULE=****.wsgi #ex: yourproject.wsgi #change this
TIMEOUT=120
echo "Starting $NAME as `whoami`"
## Activate the virtual environment
cd $DJANGODIR
source $ENVBIN/activate
cd $DJANGODIR
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
## Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
## Start your Django Unicorn
## Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec $ENVBIN/gunicorn ${DJANGO_WSGI_MODULE}:application -c=/opt/yourproject/gunicorn.conf
create service
[Unit]
Description=My Python Service
[Service]
User=root
Restart=always
Type=simple
WorkingDirectory=/opt/yourproject/
ExecStart=/usr/bin/sh gunicorn_start
[Install] WantedBy=multi-user.target
Have you tried to add "--chdir " in ExecStart?
like
ExecStart=/home/scorg/pro/sc_project/bin/gunicorn --chdir /home/scorg/pro/projects/sc/sc --workers 3 --bind unix:/home/scorg/pro/projects/sc/sc.sock sc.wsgi:application

Dockerizing Django application: ModuleNotFoundError: No module named 'X"

I've been trying to follow this guide to Dockerize a project:
Deploy and Run Django in Dokcer Container
This is the base file structure:
WFMBCM
|-WFMBCM
| |-__init__.py
| |-__pycache__
| |-setting.py
| |-url.py
| |-wsgi.py
|
|-WFMBCM_App
|-WFMBCM_db
|-manage.py
|-Dockerfile
|-requirements.txt
|-runWFMBCM.sh
Dockerfile:
FROM python:3.7
ADD WFMBCM /usr/src/app
ADD WFMBCM_App /usr/src/app
ADD WFMBCM_db /usr/src/app
ADD manage.py /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8000
CMD exec gunicorn wfmbcm.wsgi:application --bind 0.0.0.0:8000 --workers 3
requirements.txt:
Django==2.2.1
gunicorn==19.9.0
runWFMBCM.sh:
cd /home/admin/WFMBCM
echo -e "\033[0;34mGo to WFMBCM directory.\n \033[0;37m"
echo -e "\033[0;34mRemove old WFMBCM container\n \033[0;37m"
docker rm -v wfmbcm_container
echo -e "\033[0;34m\nBuild WFMBCM Docker image.\n \033[0;37m"
sudo docker build -t wfmbcm .
echo -e "\033[0;34m\nRun WFMBCM Docker image.\n \033[0;37m"
sudo docker run --name wfmbcm_container -p 8000:8000 -i -t wfmbcm
echo -e "\033[0;34m\n\nWFMBCM run-script ended!.\n \033[0;37m"
When I run runWFMBCM.sh I get the following output:
Go to WFMBCM directory.
Remove old WFMBCM container
Error response from daemon: No such container: wfmbcm_container
Build WFMBCM Docker image.
Sending build context to Docker daemon 265.2kB
Step 1/10 : FROM python:3.7
---> cc971a68c3e4
Step 2/10 : ADD WFMBCM /usr/src/app
---> Using cache
---> 302346d017e2
Step 3/10 : ADD WFMBCM_App /usr/src/app
---> Using cache
---> 18bc8eb69946
Step 4/10 : ADD WFMBCM_db /usr/src/app
---> Using cache
---> 0835393b22dc
Step 5/10 : ADD manage.py /usr/src/app
---> Using cache
---> 3ef5477e4b26
Step 6/10 : WORKDIR /usr/src/app
---> Using cache
---> 2edb019a8257
Step 7/10 : COPY requirements.txt ./
---> Using cache
---> df3ac922b7a0
Step 8/10 : RUN pip install --no-cache-dir -r requirements.txt
---> Using cache
---> ba6cf54e7dcc
Step 9/10 : EXPOSE 8000
---> Using cache
---> 94f3f4fb38c0
Step 10/10 : CMD exec gunicorn wfmbcm.wsgi:application --bind 0.0.0.0:8000 --workers 3
---> Using cache
---> db6cf2149949
Successfully built db6cf2149949
Successfully tagged wfmbcm:latest
Run WFMBCM Docker image.
[2019-05-26 09:59:36 +0000] [1] [INFO] Starting gunicorn 19.9.0
[2019-05-26 09:59:36 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
[2019-05-26 09:59:36 +0000] [1] [INFO] Using worker: sync
[2019-05-26 09:59:36 +0000] [9] [INFO] Booting worker with pid: 9
[2019-05-26 09:59:36 +0000] [10] [INFO] Booting worker with pid: 10
[2019-05-26 09:59:36 +0000] [9] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
ModuleNotFoundError: No module named 'wfmbcm'
[2019-05-26 09:59:36 +0000] [9] [INFO] Worker exiting (pid: 9)
[2019-05-26 09:59:36 +0000] [11] [INFO] Booting worker with pid: 11
[2019-05-26 09:59:36 +0000] [10] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
ModuleNotFoundError: No module named 'wfmbcm'
[2019-05-26 09:59:36 +0000] [10] [INFO] Worker exiting (pid: 10)
[2019-05-26 09:59:36 +0000] [11] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
ModuleNotFoundError: No module named 'wfmbcm'
[2019-05-26 09:59:36 +0000] [11] [INFO] Worker exiting (pid: 11)
[2019-05-26 09:59:37 +0000] [1] [INFO] Shutting down: Master
[2019-05-26 09:59:37 +0000] [1] [INFO] Reason: Worker failed to boot.
WFMBCM run-script ended!.
Why can't it find wfmbcm module? I've been staring crazy and googling without success and looking at different stack overflow questions.
I can't find any python module named wfmbcm, so I assume that it's an app in your project.
If you are on a case sensitive file system, then your file layout shows all caps for some folders and that might be (part of) the issue.
Does this project run outside of docker?
If it does, then I think that your best bet is to start the docker container and then manually install the entire app inside the container, updating the dockerfile with the steps as you go.
Every time you test a new change, make sure that you build with the --no-cache option or you may not be testing what you think you are.
Changing my DockerFile to this solved my issue:
FROM python:3.7
ADD WFMBCM /usr/src/app/WFMBCM
ADD WFMBCM_App /usr/src/app/WFMBCM_App
ADD WFMBCM_db /usr/src/app/WFMBCM_db
ADD manage.py /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8000
CMD manage.py migrate
CMD exec gunicorn WFMBCM.wsgi:application --bind 0.0.0.0:8000 --workers 10
Just Copy WFMBCM/WFMBCM/wsgi.py file in the root of project (so wsgi.py path is WFMBCM/wsgi.py)
and change CMD exec ... to this CMD exec gunicorn wsgi:application --bind 0.0.0.0:8000 --workers 3
and you'll be fine to go.

Google Cloud Platform: ImportError: No module named 'google.api.core' on deploy

This is the error I receive while I try to deploy using gcloud app deploy. I have previously successfully deployed the same app. I am able to run the app in local machine, but receives the error on deploy
the traceback:
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
[2017-08-25 10:50:23 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2017-08-25 10:50:23 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2017-08-25 10:50:23 +0000] [1] [INFO] Using worker: sync
[2017-08-25 10:50:23 +0000] [7] [INFO] Booting worker with pid: 7
[2017-08-25 10:50:23 +0000] [7] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/env/lib/python3.5/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
worker.init_process()
File "/env/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/env/lib/python3.5/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
self.wsgi = self.app.wsgi()
File "/env/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/env/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/env/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/env/lib/python3.5/site-packages/gunicorn/util.py", line 352, in import_app
__import__(module)
File "/home/vmagent/app/main.py", line 19, in <module>
app = bookshelf.create_app(config)
File "/home/vmagent/app/bookshelf/__init__.py", line 49, in create_app
model = get_model()
File "/home/vmagent/app/bookshelf/__init__.py", line 107, in get_model
from . import model_datastore
File "/home/vmagent/app/bookshelf/model_datastore.py", line 16, in <module>
from google.cloud import datastore
File "/env/lib/python3.5/site-packages/google/cloud/datastore/__init__.py", line 61, in <module>
from google.cloud.datastore.client import Client
File "/env/lib/python3.5/site-packages/google/cloud/datastore/client.py", line 33, in <module>
from google.cloud.datastore.query import Query
File "/env/lib/python3.5/site-packages/google/cloud/datastore/query.py", line 19, in <module>
from google.api.core import page_iterator
ImportError: No module named 'google.api.core'
[2017-08-25 10:50:23 +0000] [7] [INFO] Worker exiting (pid: 7)
[2017-08-25 10:50:24 +0000] [1] [INFO] Shutting down: Master
[2017-08-25 10:50:24 +0000] [1] [INFO] Reason: Worker failed to boot.
tl;dr: Upgrade your google-cloud to 0.27, and it should fix things.
I believe this is a bug with the new google-cloud dependencies. In my case, google-cloud==0.25 was pulling in these dependencies in its setup.py:
'google-cloud-core >= 0.24.0, < 0.25dev',
'google-cloud-datastore >= 1.0.0, < 2.0dev',
Just recently on 8/24 (a day before this issue was filed), the google-cloud-datastore package was updated to 1.3.0.
Unfortunately, google-cloud-datastore 1.3.0 is depending on a newer version of google-cloud-core:
'google-cloud-core >= 0.27.0, < 0.28dev',
But it seems this versioning conflict is unresolved/unwarned by pip, which uses the older version. But google-cloud-datastore wants to from google.api.core import page_iterator, even though google.api.core, which wasn't added until 0.27.0, and then everything breaks.
I believe the "bug" is in the overload broad dependency in google-cloud===0.25 (or possibly whatever version you are using).
I believe the "fix" for us is to upgrade to the latest version of google-cloud=0.27.
Though the "proper fix" is for google-cloud to improve their versioning dependencies, and not be so broad, or risk breaking backwards compatibility with already-published modules.

Python + Django debug startup on WSGI

I'm facing a crash launching with GUNICORN my App on MacOsX Sierra.
Is there any way to better understand the error message? Like to know which dependency is missing or something like that?
I searched online for more log-level info but, right now, the error is not easy to understand.
I report the error if somebody has any clue or any tool to drill down the exception and find it out!
I believe you did
I Already tried this solution and django-haystack was already there
pip install haystack
pip uninstall haysatck
pip install django-haystack
Thanks in advance
gunicorn direttoo.wsgi:application --workers 1 --bind 127.0.0.1:8001 --log-level Info
[2017-03-24 12:30:51 +0100] [3304] [INFO] Starting gunicorn 19.6.0
[2017-03-24 12:30:51 +0100] [3304] [INFO] Listening at: http://127.0.0.1:8001 (3304)
[2017-03-24 12:30:51 +0100] [3304] [INFO] Using worker: sync
[2017-03-24 12:30:51 +0100] [3307] [INFO] Booting worker with pid: 3307
[2017-03-24 11:30:51 +0000] [3307] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
File "/Users/diegobanovaz/Projects/direttoo/direttoo/wsgi.py", line 36, in <module>
application = get_wsgi_application()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/haystack/__init__.py", line 56, in <module>
maxnofile[1]))
ValueError: current limit exceeds maximum limit
[2017-03-24 11:30:51 +0000] [3307] [INFO] Worker exiting (pid: 3307)
[2017-03-24 12:30:51 +0100] [3304] [INFO] Shutting down: Master
[2017-03-24 12:30:51 +0100] [3304] [INFO] Reason: Worker failed to boot.

Heroku NameError: name 'application' is not defined

I'm trying to deploy a django app to heroku and it keeps crashing. Does anyone have any idea what I'm doing wrong?
Here is my Procfile:
web: python app/manage.py collectstatic --noinput; gunicorn --workers=4 --bind=0.0.0.0:$PORT app.settings
And here is a snippet from my heroku logs:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 456, in spawn_worker
self.wsgi = self.app.wsgi()
app = eval(obj, mod.__dict__)
File "<string>", line 1, in <module>
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 101, in wsgi
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 24, in load
self.callable = self.load()
return util.import_app(self.app_uri)
NameError: name 'application' is not defined
2014-07-04 17:58:23 [4] [INFO] Starting gunicorn 0.13.4
2014-07-04 17:58:23 [10] [ERROR] Exception in worker process:
worker.init_process()
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 250, in import_app
2014-07-04 17:58:23 [9] [INFO] Booting worker with pid: 9
2014-07-04 17:58:23 [10] [INFO] Worker exiting (pid: 10)
2014-07-04 17:58:23 [4] [INFO] Listening at: http://0.0.0.0:36148 (4)
2014-07-04 17:58:23 [7] [INFO] Booting worker with pid: 7
It says application not found. well try changing gunicorn
web: gunicorn YourProject.wsgi
I solved my own issue after doing several things, including upgrading my django install and changing my procfile to this:
web: gunicorn app.wsgi --pythonpath app --log-file -