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

时间:2020-12-31 00:07:23

标签: python gunicorn

我正在尝试在 Heroku 上使用 Gunicorn 运行 Flask 应用程序。

这是我的<style media="screen"> .box {width: 150px; height: 150px; position: absolute; z-index: 0;} .box:nth-child(1) {background-color: red; top: 0px; left: 0px;} .box:nth-child(2) {background-color: green; top: 20px; left: 50px;} .box:nth-child(3) {background-color: yellow; top: 50px; left: 100px;} .box:nth-child(4) {background-color: blue; top: 80px; left: 150px;} </style> <script type="text/javascript"> $(document).ready(function() { $('.box').draggable({stack: "div"}); }); </script> <div id="dragZone"> <div class="box" id="box1"></div> <div class="box" id="box2"></div> <div class="box" id="box3"></div> <div class="box" id="box4"></div> </div>

Procfile

我有一个名为 web: gunicorn main: app 的文件。这是顶部的一些代码:

main.py

我的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)

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

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] 从我在线阅读的内容来看似乎是正确的,但除此之外我没有发现任何问题。有人知道这是怎么回事吗?

1 个答案:

答案 0 :(得分:2)

去掉$user_id = 32; $stmt = $con->prepare("SELECT * FROM users where user_id = ?"); $stmt->bind_param('s', $value); $stmt->execute(); $result = $stmt->get_result(); foreach($result as $row) { printf ("%s \n", $row['username']); } main之间的空格:

app

Gunicorn wants a [WSGI_APP]

<块引用>

其中 web: gunicorn main:app 是模式 WSGI_APP。模块名称可以是完整的虚线路径。变量名指的是应该在指定模块中找到的 WSGI 可调用对象。

有了空格,$(MODULE_NAME):$(VARIABLE_NAME)main: 被读取为单独的参数,Gunicorn 接收一个空字符串作为它的 app