[英]Is there any alternative approach other than deploying python flask application in Google app engine flex environment?
[英]Deploying Flask app in Google App Engine resulting in "gunicorn: error: No application module specified."
把我的頭撞在桌子上,試圖讓它工作。 我正在嘗試通過 Google App Engine 在 gunicorn 上部署一個簡單的 Flask 應用程序。 訪問該應用程序時,我收到錯誤 500,顯示“gunicorn:錯誤:未指定應用程序模塊。” 在日志中。
我的布局大致是:
Main_Directory/
|-MyApp/
| |-__init__.py <- Containing majority of code
| |-templates/
| |-static/
|-app.yaml
|-main.py
|-requirements.txt
main.py
只是從MyApp
導入應用程序並實例化一個名為“app”的新實例。
requirements.txt
具有所有依賴項,包括 gunicorn。
app.yaml 如下:
runtime: python37
instance_class: F1
default_expiration: "4d 12h"
entrypoint: gunicorn -b :$PORT -w 1
env_variables:
BUCKET_NAME: "bucket_name"
handlers:
- url: /.*
script: auto
我嘗試在MyApp
文件夾中創建另一個 app.yaml 並添加服務:“默認”但這沒有幫助。 我在這里幾乎沒有想法。 我相當確定問題是因為主應用程序代碼是在MyApp
中定義的,而不是直接在Main_directory
下。 我很欣賞簡單的解決方案是將MyApp
文件夾中的所有內容提升一個級別,但我猶豫是否要這樣做,因為它會弄亂我的 Git。我認為創建 main.py 並直接實例化MyApp/__init__.py
會做把戲,但似乎並不完全是。
任何和所有的想法表示贊賞。
通常情況下,在達到我的極限並提出問題后,我找到了答案......
我從app.yaml
中刪除了入口點,並從requirements.txt
中刪除了 gunicorn。 在重新部署應用程序時,它現在可以工作了。
我覺得這不是一個解決方法,而是一種解決方法。 我仍然不確定為什么它以前不起作用。 必須有更好的解決方案來保持 gunicorn 作為要求。 我預計錯的是 yaml。
如果你想使用 gunicorn 作為你的 HTTP 服務器,你需要告訴它你的 WSGI 應用程序的位置。 這可能是您的main.py
文件中的一個app
變量,因此您可以使用:
entrypoint: gunicorn -b :$PORT -w 1 main:app
可能導致此錯誤的另一件事是缺少gunicorn.conf.py
文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.