在将Flask / Python3 / Postgres应用程序部署到App Engine标准环境后,我收到了以下错误消息。有关Psycopg2软件包的警告值得关注,但不是导致应用程序无法运行的原因。相反,它是gunicorn的无效命令行参数,由GAE提供,而不是我提供。有人能够成功将使用Postgres的Python3 Flask部署到标准环境中吗?
这是日志文件输出:
2018-12-11 02:51:37 +0000] [3738] [INFO] Booting worker with pid: 3738
2018-12-11 02:51:37 default[20181210t140744] /env/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
2018-12-11 02:51:37 default[20181210t140744] """)
2018-12-11 02:51:38 default[20181210t211942] usage: gunicorn [-h] [--debug] [--args]
2018-12-11 02:51:38 default[20181210t211942] gunicorn: error: unrecognized arguments: main:app --workers 1 -c /config/gunicorn.py
2018-12-11 02:51:38 default[20181210t211942] [2018-12-11 02:51:38 +0000] [882] [INFO] Worker exiting (pid: 882)
答案 0 :(得分:1)
默认情况下,如果未在app.yaml中定义entrypoint
,则App Engine将在app
中查找名为main.py
的应用。如果您查看Github中的官方代码示例,它将通过声明以下内容在main.py文件中进行处理:
app = Flask(__name__)
或者,可以通过将entrypoint
添加到指向另一个文件的app.yaml来进行配置。例如,如果您在名为prod的文件中声明app:
entrypoint: gunicorn -b :$PORT prod.app
您将找到有关入口点配置here的其他详细信息。
答案 1 :(得分:0)
从上面的评论和答案来看,问题似乎出在我的应用中。我通过在一个简单的应用程序上本地运行gunicorn来确认这一点,但没有遇到任何困难,但是在运行真正的应用程序时却失败了。
一个罪魁祸首是使用 argparse ,我在使用它,因此在本地工作时可以在命令行中添加“ debug”参数。将该代码移至if __name__ == '__main__':
部分,可以在本地使用gunicorn时使应用正常运行。
但是在部署到GAE时仍然失败:
2018-12-12 20:09:16 default[20181212t094625] [2018-12-12 20:09:16 +0000] [8145] [INFO] Booting worker with pid: 8145
2018-12-12 20:09:16 default[20181212t094625] /env/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
2018-12-12 20:09:16 default[20181212t094625] """)
2018-12-12 20:09:16 default[20181212t094625] [2018-12-12 20:09:16 +0000] [8286] [INFO] Booting worker with pid: 8286
2018-12-12 20:09:16 default[20181212t094625] /env/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
2018-12-12 20:09:16 default[20181212t094625] """)
2018-12-12 20:09:19 default[20181212t094625] usage: gunicorn [-h] [--debug] [--args]
2018-12-12 20:09:19 default[20181212t094625] gunicorn: error: unrecognized arguments: -b :8081 main:app
2018-12-12 20:09:19 default[20181212t094625] [2018-12-12 20:09:19 +0000] [8145] [INFO] Worker exiting (pid: 8145)
这是app.yaml(减去SendGrid的环境变量):
runtime: python37
env: standard
#threadsafe: true
entrypoint: gunicorn --workers 2 --bind :5000 main:app
#runtime_config:
# python_version: 3
# This beta setting is necessary for the db hostname parameter to be able to handle a URI in the
# form “/cloudsql/...” where ... is the instance given here:
beta_settings:
cloud_sql_instances: provost-access-148820:us-east1:cuny-courses