简体   繁体   English

Flask Heroku 上的应用程序在部署后出现应用程序错误

[英]Flask App on Heroku getting Application Error after deploy

I'm trying to run a Flask app with Gunicorn on Heroku.我正在尝试在 Heroku 上使用 Gunicorn 运行 Flask 应用程序。

This is my Procfile :这是我的Procfile

web: gunicorn main: app

I have a file called main.py .我有一个名为main.py的文件。 Here is some of the code at the top:这是顶部的一些代码:

from flask import Flask, redirect, url_for, render_template, request, session, flash
from datetime import timedelta, datetime
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.secret_key = "{Secret Key}"
app.permanent_session_lifetime = timedelta(minutes=10)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.sqlite3'
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db = SQLAlchemy(app)

....

if __name__ == "__main__":
    db.create_all()
    app.run(debug=True)

My requirements.txt :我的requirements.txt

click==7.1.2
Flask==1.1.2
Flask-SQLAlchemy==2.4.4
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
SQLAlchemy==1.3.22
Werkzeug==1.0.1

I'm getting this in my logs:我在我的日志中得到这个:

2020-12-31T00:00:05.879585+00:00 app[web.1]: Failed to parse '' as an attribute name or function call.
2020-12-31T00:00:05.880396+00:00 app[web.1]: [2020-12-31 00:00:05 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-12-31T00:00:05.887417+00:00 app[web.1]: Failed to parse '' as an attribute name or function call.
2020-12-31T00:00:05.888296+00:00 app[web.1]: [2020-12-31 00:00:05 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-12-31T00:00:06.139402+00:00 app[web.1]: [2020-12-31 00:00:06 +0000] [4] [INFO] Shutting down: Master
2020-12-31T00:00:06.139670+00:00 app[web.1]: [2020-12-31 00:00:06 +0000] [4] [INFO] Reason: App failed to load.
2020-12-31T00:00:06.291109+00:00 heroku[web.1]: Process exited with status 4
2020-12-31T00:00:06.360098+00:00 heroku[web.1]: State changed from up to crashed
2020-12-31T00:00:12.000891+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" [some extra stuff]
2020-12-31T00:00:12.118356+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" [some extra stuff]

The Procfile looks to be right from what I've read online but otherwise I don't see anything wrong with this.根据我在网上阅读的内容, Procfile看起来是正确的,但除此之外我没有发现任何问题。 Does anyone know what's going on with this?有谁知道这是怎么回事?

Remove the space between main and app :删除mainapp之间的空格:

web: gunicorn main:app

Gunicorn wants a [WSGI_APP] Gunicorn 想要一个[WSGI_APP]

Where WSGI_APP is of the pattern $(MODULE_NAME):$(VARIABLE_NAME) .其中WSGI_APP是模式$(MODULE_NAME):$(VARIABLE_NAME) The module name can be a full dotted path.模块名称可以是完整的点路径。 The variable name refers to a WSGI callable that should be found in the specified module.变量名称指的是应该在指定模块中找到的 WSGI 可调用对象。

With the space, main: and app are read as separate arguments and Gunicorn receives an empty string as its VARIABLE_NAME .对于空格, main:app被读取为单独的 arguments 并且 Gunicorn 收到一个空字符串作为其VARIABLE_NAME

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试将 flask 应用程序部署到 heroku,缩放测功机后出现 h14 错误 - Trying to deploy flask app to heroku, getting h14 error after scaling dyno 将 flask 应用程序部署到 heroku 服务器后出现找不到模块错误 - getting module not found error after deploying flask app to heroku server 应用程序错误:我的 Flask-web-app 已成功部署在 Heroku 上,但在加载站点时收到应用程序错误 - Application error: My Flask-web-app is successfully deploy on Heroku but receiving application error when loading site Django 应用程序部署到 Heroku,应用程序错误, - Django app deploy to Heroku, Application Error, Heroku 部署 Flask 应用程序时出现“应用程序错误” - Heroku "Application error" when deploying Flask app 将 Python Flask 应用程序部署到 Heroku R10 错误 - Deploy Python Flask App to Heroku R10 Error 无法将 Python-Flask 应用程序部署到 Heroku(ipython 版本错误) - Unable to Deploy Python-Flask App to Heroku (ipython Version Error) 尝试在 Heroku 上部署 flask 应用程序时出现 PyObjc 错误 - PyObjc error while trying to deploy flask app on Heroku 将具有 heroku 数据库的 python flask 应用程序部署到 Z3115FB34DFCB5BA8AA049707C596B73Z3 - Deploy a python flask app with heroku database to heroku Heroku flask应用程序部署:ImportError:未命名模块 - Heroku flask application deploy: ImportError: No module named
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM