0

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

Henrik
  • 191
  • 1
  • 17
  • 1
    please add content of your `app.yaml` – yedpodtrzitko Apr 08 '20 at 07:39
  • 1
    Based on the strack trace, note that you are using Python 3.7 and the [documentation](https://cloud.google.com/appengine/docs/standard/python/getting-started/hosting-a-static-website) you shared is for Python 2.7. Are you using any web framework, such as Django or Flask? Most web applications use a WSGI server like Gunicorn, uWSGI or Waitress. I encourage you to take a look at the following [documentation](https://cloud.google.com/appengine/docs/flexible/python/runtime#application_startup). At first glance, it looks like you may be missing some dependencies when starting up your application. – sllopis Apr 08 '20 at 10:52
  • Also, please post your `app.yaml` file content. Keep me posted! – sllopis Apr 08 '20 at 11:04
  • Thank you all for the comments - I've adjusted my app.yaml content to python 2.7 as you mentioned @sllopis and it worked (screenshot added). My question now has shifted entirely to how do I get this to work with Python 3.7, but that may warrant an entirely new question to post. – Henrik Apr 08 '20 at 14:17
  • For this application I am not using either Django or Flask. Is there one that is preferable/easier to use over the other for website hosting & integrating frontend triggers to backend activity? – Henrik Apr 08 '20 at 14:18
  • Hi @Henrik, I am glad that you solved the issue. I will post the solution as an answer for other community users who may run into this issue in the future. Regarding your second question, it is always best practice to apply the "separation of concerns" principle, and ask in a new question. Nonetheless, I also answered your question below. Hope it helps! – sllopis Apr 09 '20 at 08:04
  • Thank you @sllopis for answering both questions. Yes I assumed that it would be best practice to post a new question regarding migration, but I appreciate you offering a quick solution below. – Henrik Apr 09 '20 at 15:15

1 Answers1

1

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.

sllopis
  • 2,292
  • 1
  • 8
  • 13