简体   繁体   English

访问 Heroku 部署的 Flask 应用程序时出错

[英]Errors when visiting Heroku-deployed Flask app

I have a very, very simple Flask app that I'm testing on Heroku just to see if it works.我有一个非常非常简单的 Flask 应用程序,我正在 Heroku 上进行测试,看看它是否有效。 I've tried connecting it to my GitHub repo and using Heroku CLI but neither changes the outcome.我已经尝试将它连接到我的 GitHub 存储库并使用 Heroku CLI,但都没有改变结果。

from flask import Flask

app = Flask("__name__")


@app.route("/api", methods=["GET"])
def get():
    return {"success": "much success"}


app.run(debug=True)

I followed a tutorial on Udemy on deploying to Heroku but it's not working.我遵循了关于 Udemy 的关于部署到 Heroku 的教程,但它不起作用。 I was told to add these files to my root:我被告知将这些文件添加到我的根目录:

// runtime.txt
python-3.8.3

// requirements.txt
// created by running pip3 freeze > requirements.txt
// manually added 'uwsgi'
appdirs==1.4.3
attrs==19.3.0
black==19.10b0
click==7.1.1
Flask==1.1.2
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
pathspec==0.8.0
regex==2020.4.4
toml==0.10.0
typed-ast==1.4.1
Werkzeug==1.0.1
uwsgi

// uwsgi.ini
[uwsgi]
http-socket = :$(PORT)
master =true
die-on-term = true
module = app:app 
memory-report = true

// Procfile
web: uwsgi uwsgi.ini

I get an 'Application Error' when I visit my app on Heroku.我在 Heroku 上访问我的应用程序时收到“应用程序错误”。 This is what Heroku logs shows:这是 Heroku 日志显示的内容:

2020-04-20T20:32:57.218876+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ninny-code-flask.herokuapp.com request_id=d355b4b9-c532-4971-91fa-e3421ca98971 fwd="104.178.145.19" dyno= connect= service= status=503 bytes= protocol=https

I think you are missing the PORT which you need to assigning using the env variable $PORT (provided by Heroku)我认为您缺少需要使用 env 变量 $PORT (由 Heroku 提供)分配的 PORT

app.run(debug=False, port=int(os.environ.get("PORT", 5000)), host='0.0.0.0')

Looking at your debug output, I see that the script is exiting/crashed due to the port already in use.查看您的调试 output,我看到由于端口已在使用中,脚本正在退出/崩溃。 Check if you have any other local server running on the same port on the command line or service.检查是否有任何其他本地服务器在命令行或服务的同一端口上运行。 See this line?看到这条线了吗? it tells you what's the reason it failed.它告诉你失败的原因是什么。

OSError: [Errno 98] Address already in use

Find the pid process and shut it down/terminate it.找到 pid 进程并将其关闭/终止。 There must be another process listening on the port.必须有另一个进程正在侦听该端口。 You might find out that process by using the following command:您可以使用以下命令找出该过程:

$ lsof -i :5000

and then run sudo to kill the process.然后运行 sudo 杀死进程。

sudo kill -9 <process_id>

However, I see now Error code h10 in heroku logs.但是,我现在在 heroku 日志中看到错误代码 h10

This error is thrown if in a Node.如果在 Node.js 中,则会引发此错误。 js environment, you forget to set a start script.在 Node.js 环境中,您忘记设置启动脚本。 Heroku uses this script to start your app so if it is missing, it would throw an H10-App crashed error code message. Heroku 使用此脚本启动您的应用程序,因此如果缺少它,它将抛出 H10-App 崩溃错误代码消息。

Check your Procfile file, look up for spacing errors.检查您的 Procfile 文件,查找间距错误。

Wrong web : node server.js
Correct web:node server.js

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

相关问题 如何将数据文件上传到 Heroku 部署的 Dash web 应用程序 - How to upload data file to a Heroku-deployed Dash web app 数据库更改时,Heroku部署的Django网页不会更新 - Heroku-deployed Django webpage doesn't update when DB changes 部署在 heroku 上时,Flask 应用程序出现 H10 错误 - H10 Error in Flask App when deployed on heroku 当烧瓶应用程序部署到Heroku时,为什么不导入flask-bootstrap base.html模板? - Why won't the flask app import the flask-bootstrap base.html template when deployed to Heroku? 在已部署的 Flask 应用程序 (Heroku) 上使用 OpenCV - Use OpenCV on deployed Flask app (Heroku) 我在heroku上部署了flask应用程序,它立即崩溃了 - I deployed a flask app on heroku , it was crashed immediately Flask 应用程序部署在 Heroku 线程问题 - Flask app deployed on Heroku threading problem Heroku 在本地工作但在部署时崩溃 - Flask - Heroku works locally but crashes when deployed - Flask Flask App通过Heroku部署时由于Error = H10而导致应用程序错误 - Flask App results in Application Error when deployed through Heroku due to Error=H10 Flask 应用程序在部署在 heroku 上并尝试打开 excel 文件时出错 - Flask app gives error when deployed on heroku and trying to open excel file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM