python-3.x - Error: Bad Gateway 502 when opening Google App Engine Python Domain - answerstu - answerstu.com answerstu

Error: Bad Gateway 502 when opening Google App Engine Python Domain

When I'm visiting my website (https://osm-messaging-platform.appspot.com), I get this error on the main webpage:

502 Bad Gateway. nginx/1.14.0 (Ubuntu).

It's really weird, since when I run it locally

python app.py

I get no errors, and my app and the website load fine.

I've already tried looking it up, but most of the answers I've found on stack overflow either have no errors or don't relate to me. Here is the error when I look at my GCloud logs:

019-02-07 02:07:05 default[20190206t175104]  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'
2019-02-07 02:07:05 default[20190206t175104]  [2019-02-07 02:07:05 
+0000] [25] [INFO] Worker exiting (pid: 25)
2019-02-07 02:07:05 default[20190206t175104]  [2019-02-07 02:07:05 
+0000] [8] [INFO] Shutting down: Master
2019-02-07 02:07:05 default[20190206t175104]  [2019-02-07 02:07:05 
+0000] [8] [INFO] Reason: Worker failed to boot.

And here are the contents of my app.yaml file:

runtime: python37

handlers:
 # This configures Google App Engine to serve the files in the app's 
static
 # directory.
 - url: /static
 static_dir: static


- url: /.*
  script: auto

I expected it to show my website, but it didn't. Can anyone help?

1 Answer

  1. Oscar- Reply

    2019-11-14

    The error is produced because the App Engine Standard Python37 runtime handles the requests in the main.py file by default. I guess that you don't have this file and you are handling the requests in the app.py file.

    Also the logs traceback is pointing to it: ModuleNotFoundError: No module named 'main'

    Change the name the name of the app.py file to main.py and try again.

    As a general rule it is recommended to follow this file structure present in the App Engine Standard documention:

    • your-app/
      • app.yaml
      • main.py
      • requirements.txt
      • static/
        • script.js
        • style.css
      • templates/
        • index.html


    I believe this would be overkill for your situation but If you need a custom entrypoint read this Python3 runtime documentation to know more about how to configure it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>