错误:打开Goog​​le App Engine Python域时,网关502错误

时间:2019-02-07 02:23:05

标签: python-3.x google-app-engine gcloud

当我访问自己的网站(https://osm-messaging-platform.appspot.com)时,在主网页上出现此错误:

502 Bad Gateway. nginx/1.14.0 (Ubuntu).

这真的很奇怪,因为当我在本地运行时

python app.py

我没有任何错误,我的应用程序和网站均正常运行。

我已经尝试过查找它,但是我在堆栈溢出中找到的大多数答案都没有错误,或者与我无关。当我查看我的GCloud日志时,这是错误:

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.

这是我的app.yaml文件的内容:

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

我希望它能显示我的网站,但没有。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

由于默认情况下App Engine标准Python37运行时会处理main.py文件中的请求,因此产生了错误。我猜您没有此文件,而您正在处理app.py文件中的请求。

日志追溯也指向它:ModuleNotFoundError: No module named 'main'

app.py文件的名称更改为main.py,然后重试。

通常,建议遵循App Engine Standard documention中存在的以下文件结构:

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


我认为这对于您的情况可能会过大,但是如果您需要自定义entrypoint,请阅读t his Python3 runtime documentation,以了解有关如何进行配置的更多信息。

答案 1 :(得分:0)

我的错误是命名与main.py冲突的主应用程序“ main”。它在本地运行良好,因为它不使用main.py。我将其更改为root,一切正常。我花了整整一天的时间来解决它。