I'm trying to deploy my app but I keep getting this error on the website:
Error: Server Error The server encountered an error and could not complete your request. Please try again in 30 seconds.
The error logs for this are:
2021-07-15 12:36:04 default[20210715t122912] [2021-07-15 12:36:04 0000] [20] [INFO] Worker exiting (pid: 20)
2021-07-15 12:36:04 default[20210715t122912] [2021-07-15 12:36:04 0000] [23] [ERROR] Exception in worker process
2021-07-15 12:36:04 default[20210715t122912] Traceback (most recent call last): File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/workers/gthread.py", line 92, in init_process super().init_process() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/workers/base.py", line 119, in init_process self.load_wsgi() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi self.wsgi = self.app.wsgi() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 49, in load return self.load_wsgiapp() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp return util.import_app(self.app_uri) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/util.py", line 358, in import_app mod = importlib.import_module(module) File "/opt/python3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 855, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/srv/main.py", line 1, in <module> from booking.wsgi import application File "/srv/booking/wsgi.py", line 12, in <module> from django.core.wsgi import get_wsgi_application ModuleNotFoundError: No module named 'django'
I already have a main.py file:
main.py
from booking.wsgi import application
app = application
I also have an app.yaml file and these are the contents:
runtime: python39
entrypoint: gunicorn -b :$PORT booking.wsgi
Any thoughts?
CodePudding user response:
So the issue is you're not installing the requirements on Google App Engine (GAE), as Jameel Hamdan pointed out.
The fix is to put all your requirements in a requirements.txt
file as described here.
The other thing is that you are using an entrypoint in the app.yaml
. There's 2 issues with this:
- Your entrypoint is incorrect. Considering the way you've set it up, your entrypoint should be
entrypoint: gunicorn -b :$PORT main:app
. This way you tellgunicorn
to look for theapp
object in themain.py
file. - Since you're using a non-default entrypoint, you'll need to make sure
gunicorn
is in yourrequirements.txt
as described in the GAE docs for entrypoint. I know it's a bit implicit with this sentence: App Engine will also automatically add the gunicorn to your requirements.txt file if you don't specify the entrypoint field. But I am sure you needgunicorn
in yourrequirements.txt
.
Sidenote
Since you're likely not using a requirements.txt
file, you're likely also not using a virtualenv
for your local development. You should always use a virtualenv
. See the relevant documentation. Better to get used to doing this now, so you will be doing this without thinking for next projects.
Note that this is also recommended in the GAE docs for the requirements.txt
I linked earlier.
EDIT
Try changing your app.yaml
to the default app.yaml
for Django:
runtime: python39
handlers:
# This configures Google App Engine to serve the files in the app's static
# directory.
- url: /static
static_dir: static/
# This handler routes all requests not caught above to your main app. It is
# required when static routes are defined, but can be omitted (along with
# the entire handlers section) when there are no static files defined.
- url: /.*
script: auto