Search code examples
google-app-engineweb-testingbad-gateway

Hosting website on Google App Engine | 502 Bad Gateway | Worker failed to boot (logger)


I am following this guide to host a static website on GAE. The screenshot is of my folder structure, where 'formicidae' is my project's root directory and 'www' contains some HTML, CSS, JS, and image files.

Deploying is fine with gcloud app deploy, but I am getting a 502 bad gateway nginx error when I want to browse my application with gcloud app browse.

Checking the logger, I was getting a ModuleNotFoundError: No module named 'main' error, so I added a new entrypoint in my app.yaml, that looks like entrypoint: gunicorn -b :$PORT formicidae.wsgi --timeout 120 (also extends the timeout).

This didn't fix the issue so I added a dummy main.py script with from formicidae import app, but received the error ModuleNotFoundError: No module named 'formicidae' in my logger.

I changed it to from www import app but received ImportError: cannot import name 'app' from 'www' (unknown location).

I'm not sure if I'm on the right track with one of these solutions and should just replace 'formicidae' or 'www' with something else, or if there is a different solution altogether.

Here is the full logger output showing me the original error of no module named 'main'

Traceback (most recent call last): File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process super(ThreadWorker, self).init_process() File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process self.load_wsgi() File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi self.wsgi = self.app.wsgi() File "/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load return self.load_wsgiapp() File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp return util.import_app(self.app_uri) File "/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app __import__(module) ModuleNotFoundError: No module named 'main'

EDIT: Added screenshot of app.yaml content

enter image description here

enter image description here


Solution

  • Based on the strack trace, note that you are using Python 3.7 and the documentation you shared is for Python 2.7. Please adjust your app.yaml file accordingly.

    The following documentation will help you on the migration to Python 3 standard runtime.

    Please do note that when using Python 3 runtime, your app will make use of a web framework like Django or Flask to route the requests. Python 2 used to do this by defining URL handlers in the app.yaml file thus far.