使用 Psycopg2 部署 Flask 应用程序时 Heroku H10 错误

发布于 2025-01-20 02:15:05 字数 3224 浏览 3 评论 0原文

在本地运行,但在部署到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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪是无色的血 2025-01-27 02:15:05

我必须创建一个具有相同凭证的Postgres服务器。为此,我使用了pgadmin。

I had to create a postgres server that had the same credentials. For that I used pgAdmin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文