使用 Psycopg2 部署 Flask 应用程序时 Heroku H10 错误
在本地运行,但在部署到Heroku(请参阅错误消息)时。
我尝试使用Python版本添加一个Runtime.txt文件,并在StackowerFlow上尝试了大多数建议: 更改有关端口或procfile的内容。但是我显然错过了一些东西。
app.py
from flask import Flask, render_template, request, flash, session, Markup, redirect, url_for
import cgi
import psycopg2
connect = psycopg2.connect(
host = "ec2-18-210-64-223.compute-1.amazonaws.com",
dbname = "d871o598hou16e",
user = "ntvbkqtnpwzevj",
password = "882d0df267e2ce38ec994997b52e1a0bff78d949d3c3ad15b1b1e138b1fc4e6a",
port = "5432")
# the above are credentials from Heroku Postgres add-on.
cur = connect.cursor()
#...
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def home():
return render_template("index.html")
port = int(os.environ.get("PORT", 5000))
if __name__ == "__main__":
app.secret_key="lol"
app.run(host='0.0.0.0', port=port, debug=True)
connect.commit()
cur.close()
connect.close()
procfile
web: gunicorn app:app
click==8.0.3
colorama==0.4.4
Flask==2.0.2
gunicorn==20.1.0
itsdangerous==2.0.1
Jinja2==3.0.3
MarkupSafe==2.0.1
psycopg2==2.9.3
Werkzeug==2.0.2
。
2022-04-08T19:36:33.582752+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2022-04-08T19:36:33.582842+00:00 app[web.1]: self.reap_workers()
2022-04-08T19:36:33.582852+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2022-04-08T19:36:33.582967+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2022-04-08T19:36:33.582997+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2022-04-08T19:36:33.744976+00:00 heroku[web.1]: Process exited with status 1
2022-04-08T19:36:33.871744+00:00 heroku[web.1]: State changed from up to crashed
2022-04-08T19:36:35.753303+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=movie-recommendation-service-o.herokuapp.com request_id=ad363000-ea61-432a-8b24-c0d0214aa899 fwd="5.33.58.163" dyno= connect= service= status=503 bytes= protocol=https
2022-04-08T19:36:36.100503+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=movie-recommendation-service-o.herokuapp.com request_id=2b41172e-8bd5-4ef0-ad1c-3b906d7686da fwd="5.33.58.163" dyno= connect= service= status=503 bytes= protocol=https
2022-04-08T19:36:45.395444+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/addMovie" host=movie-recommendation-service-o.herokuapp.com request_id=331c5ae1-73c0-4b14-b73a-53a12ef6f61f fwd="5.33.58.163" dyno= connect= service= status=503 bytes= protocol=https
2022-04-08T19:36:45.643071+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=movie-recommendation-service-o.herokuapp.com request_id=bc3d9cbe-e54a-47b7-aabd-ab2b75377e7e fwd="5.33.58.163" dyno= connect= service= status=503 bytes= protocol=https
要求 并尝试了我没有运气的所有解决方案。如您所知,我在这里是新手,所以希望这篇文章还可以。请提供示例文本以澄清。
Runs locally, but not when deployed to Heroku (see error message).
I tried adding a runtime.txt file with the Python version, and tried most of suggestions to similar questions here on Stackowerflow:
To change something about the Port or the Procfile. But I clearly missed something.
app.py
from flask import Flask, render_template, request, flash, session, Markup, redirect, url_for
import cgi
import psycopg2
connect = psycopg2.connect(
host = "ec2-18-210-64-223.compute-1.amazonaws.com",
dbname = "d871o598hou16e",
user = "ntvbkqtnpwzevj",
password = "882d0df267e2ce38ec994997b52e1a0bff78d949d3c3ad15b1b1e138b1fc4e6a",
port = "5432")
# the above are credentials from Heroku Postgres add-on.
cur = connect.cursor()
#...
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def home():
return render_template("index.html")
port = int(os.environ.get("PORT", 5000))
if __name__ == "__main__":
app.secret_key="lol"
app.run(host='0.0.0.0', port=port, debug=True)
connect.commit()
cur.close()
connect.close()
Procfile
web: gunicorn app:app
requirements.txt
click==8.0.3
colorama==0.4.4
Flask==2.0.2
gunicorn==20.1.0
itsdangerous==2.0.1
Jinja2==3.0.3
MarkupSafe==2.0.1
psycopg2==2.9.3
Werkzeug==2.0.2
Heroku error log (all there is)
2022-04-08T19:36:33.582752+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2022-04-08T19:36:33.582842+00:00 app[web.1]: self.reap_workers()
2022-04-08T19:36:33.582852+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2022-04-08T19:36:33.582967+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2022-04-08T19:36:33.582997+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2022-04-08T19:36:33.744976+00:00 heroku[web.1]: Process exited with status 1
2022-04-08T19:36:33.871744+00:00 heroku[web.1]: State changed from up to crashed
2022-04-08T19:36:35.753303+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=movie-recommendation-service-o.herokuapp.com request_id=ad363000-ea61-432a-8b24-c0d0214aa899 fwd="5.33.58.163" dyno= connect= service= status=503 bytes= protocol=https
2022-04-08T19:36:36.100503+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=movie-recommendation-service-o.herokuapp.com request_id=2b41172e-8bd5-4ef0-ad1c-3b906d7686da fwd="5.33.58.163" dyno= connect= service= status=503 bytes= protocol=https
2022-04-08T19:36:45.395444+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/addMovie" host=movie-recommendation-service-o.herokuapp.com request_id=331c5ae1-73c0-4b14-b73a-53a12ef6f61f fwd="5.33.58.163" dyno= connect= service= status=503 bytes= protocol=https
2022-04-08T19:36:45.643071+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=movie-recommendation-service-o.herokuapp.com request_id=bc3d9cbe-e54a-47b7-aabd-ab2b75377e7e fwd="5.33.58.163" dyno= connect= service= status=503 bytes= protocol=https
I've seen all similar questions and tried the all solutions I understood without luck. As you can tell, Im new here so hope this post is ok. Please provide example text to clarify.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我必须创建一个具有相同凭证的Postgres服务器。为此,我使用了pgadmin。
I had to create a postgres server that had the same credentials. For that I used pgAdmin.