[英]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.