我正在关注 Youtube Tutorial 使用 Python、Twilio 和 Flask 制作 WhatsApp 机器人。 一切都很好,直到在 Heroku 上部署机器人,该应用程序已成功部署,但是当我尝试打开该应用程序时,它失败并显示以下屏幕
运行后heroku logs --tail
这是我得到的
» Warning: heroku update available from 7.53.0 to 7.53.1.
2021-05-10T17:05:27.833066+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2021-05-10T17:05:30.957905+00:00 app[web.1]: bash: gunicorn: command not found
2021-05-10T17:05:31.000000+00:00 app[api]: Build succeeded
2021-05-10T17:05:31.056144+00:00 heroku[web.1]: Process exited with status 127
2021-05-10T17:05:31.138486+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-10T17:05:31.179296+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-10T17:05:37.281917+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2021-05-10T17:05:40.782645+00:00 app[web.1]: bash: gunicorn: command not found
2021-05-10T17:05:40.858440+00:00 heroku[web.1]: Process exited with status 127
2021-05-10T17:05:40.962293+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-10T17:05:58.300980+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=w28bot.herokuapp.com request_id=c092082c-596c-4e11-9139-38a6353d1b4c fwd="102.166.25.202" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T17:06:00.776174+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=w28bot.herokuapp.com request_id=5407d07b-f580-460f-bd67-dec4e694623b fwd="102.166.25.202" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T17:12:59.818806+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-10T17:13:05.166161+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2021-05-10T17:13:08.574926+00:00 app[web.1]: bash: gunicorn: command not found
2021-05-10T17:13:08.649127+00:00 heroku[web.1]: Process exited with status 127
2021-05-10T17:13:08.726439+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-10T17:13:11.111267+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=w28bot.herokuapp.com request_id=5f63c437-dc89-45d2-8e2d-6a16fb809bdf fwd="102.166.25.202" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T17:13:14.439557+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=w28bot.herokuapp.com request_id=6290cd2f-5238-4f51-a99e-dcd9858177b5 fwd="102.166.25.202" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T17:30:17.642449+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=w28bot.herokuapp.com request_id=06e9bf70-d722-4829-8372-a93002291922 fwd="102.167.29.105" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T17:30:21.211441+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=w28bot.herokuapp.com request_id=27a55213-c14e-49ff-a6dd-bd627c396050 fwd="102.167.29.105" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T17:33:01.744191+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=w28bot.herokuapp.com request_id=95414e5b-7b7e-4a89-9606-092fe2eadf20 fwd="102.167.29.105" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T17:33:03.557619+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=w28bot.herokuapp.com request_id=dee3b35e-f733-434f-beb8-7fd58bfd0ead fwd="102.167.29.105" dyno= connect= service= status=503 bytes= protocol=https
这是我的 app.py 代码
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, World!"
@app.route("/sms", methods=['POST'])
def sms_reply():
"""Respond to incoming calls with a simple text message."""
# Fetch the message
msg = request.form.get('Body')
# Create reply
resp = MessagingResponse()
resp.message("You said: {}".format(msg))
return str(resp)
if __name__ == "__main__":
app.run(debug=True)
这是我的Procfile
web gunicorn app: app
这是我的要求.txt
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
Flask==1.1.2
gunicorn==20.1.0
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.3
MarkupSafe==1.1.1
PyJWT==1.7.1
Pysocks==1.7.1
pytz==2021.1
requests==2.25.1
six==1.16.0
twilio==6.58.0
urllib3==1.26.4
Werkzeug==1.0.1
我们将不胜感激任何形式的帮助。
答案 0 :(得分:1)
gunicorn
是一个 pip
包,链接:https://pypi.org/project/gunicorn/。在您的 requirements.txt
中添加 gunicorn
。
新requirements.txt
:
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
Flask==1.1.2
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.3
MarkupSafe==1.1.1
PyJWT==1.7.1
pytz==2021.1
requests==2.25.1
six==1.16.0
twilio==6.58.0
urllib3==1.26.4
Werkzeug==1.0.1
gunicorn
这个 Procfile
对我有用:
web: gunicorn app:app --log-file=-
还要确保您有一个 runtime.txt
,例如:
python-3.9.5
答案 1 :(得分:0)
我实际上通过从头重新创建应用程序找到了解决方案,原来我没有在我的虚拟环境中安装 gunicorn,这可以通过运行 $ pip install gunicorn
来实现
我不知道这是否正是导致狂喜的原因,但现在我很高兴它可以完全运行。
谢谢@KetZoomer 的帮助。