问题描述
我有一个非常非常简单的Flask应用程序,我正在Heroku上对其进行测试,以查看其是否有效.我曾尝试使用Heroku CLI将其连接到GitHub存储库,但都没有改变结果.
I have a very, very simple Flask app that I'm testing on Heroku just to see if it works. I've tried connecting it to my GitHub repo and using Heroku CLI but neither changes the outcome.
from flask import Flask
app = Flask("__name__")
@app.route("/api", methods=["GET"])
def get():
return {"success": "much success"}
app.run(debug=True)
我按照有关Udemy的教程进行了部署到Heroku的教程,但是该教程无法正常工作.有人告诉我将这些文件添加到我的根目录:
I followed a tutorial on Udemy on deploying to Heroku but it's not working. 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
在Heroku上访问我的应用程序时,出现应用程序错误".这是Heroku日志显示的内容:
I get an 'Application Error' when I visit my app on Heroku. This is what Heroku logs shows:
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
推荐答案
查看您的调试输出,我看到由于正在使用的端口,该脚本正在退出/崩溃.检查是否在命令行或服务的同一端口上运行任何其他本地服务器.看到这条线?它告诉您失败的原因.
Looking at your debug output, I see that the script is exiting/crashed due to the port already in use.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
找到pid进程,然后将其关闭/终止.必须在端口上侦听另一个进程.您可以使用以下命令找出该过程:
Find the pid process and shut it down/terminate it. There must be another process listening on the port. You might find out that process by using the following command:
$ lsof -i :5000
然后运行sudo终止进程.
and then run sudo to kill the process.
sudo kill -9 <process_id>
但是,我现在在heroku日志中看到错误代码h10 .
However, I see now Error code h10 in heroku logs.
如果在节点中,则会引发此错误.在js环境中,您忘记设置启动脚本了.Heroku使用此脚本来启动您的应用程序,因此如果缺少该应用程序,则会抛出H10-App崩溃的错误代码消息.
This error is thrown if in a Node. js environment, you forget to set a start script . Heroku uses this script to start your app so if it is missing, it would throw an H10-App crashed error code message.
检查您的Procfile文件,查找间距错误.
Check your Procfile file, look up for spacing errors.
Wrong web : node server.js
Correct web:node server.js
这篇关于访问Heroku部署的Flask应用程序时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!