【问题标题】:Heroku Application Error python flaskHeroku应用程序错误python烧瓶
【发布时间】:2016-11-04 08:13:23
【问题描述】:

我正在努力做好生产准备。 将来拥有我自己的域并调用条带。 但是我在部署我的应用时遇到问题。

'geeni.py'

class ChargeUser(Resource):
    def post(self):
        jsonData = request.get_json(force=True)
        stripeid = jsonData['stripeid_customer']
        currency = jsonData['currency']
        amount = jsonData['amount']
        apiKey = jsonData['api_key']
        try:
            stripe.Charge.create(amount = amount, source=stripeid, currency=currency)
            return jsonify({'Msg':'Charged!'})
        except:
            raise

api.add_resource(ChargeUser,'/')
if __name__ == "__main__":
    port = int(os.environ.get("PORT", 5000))
    app.run(host='0.0.0.0', port=port)

在我的 ProcFile 下我有 以下内容

"web gunicorn geeni:app"

所以我打电话

heroku ps:scale web=1

立即向我抛出此错误:

    2016-11-04T09:07:19.592920+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2016-11-04T09:07:20.540914+00:00 app[web.1]: 2016-11-04 09:07:20 [3] [INFO] Handling signal: term
2016-11-04T09:07:20.541241+00:00 app[web.1]: 2016-11-04 09:07:20 [7] [INFO] Worker exiting (pid: 7)
2016-11-04T09:07:20.752145+00:00 app[web.1]: 2016-11-04 09:07:20 [3] [INFO] Shutting down: Master
2016-11-04T09:07:20.932424+00:00 heroku[web.1]: Process exited with status 0
2016-11-04T09:07:46.047825+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-11-04T09:07:46.047990+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-11-04T09:07:46.144820+00:00 heroku[web.1]: Process exited with status 137
2016-11-04T09:07:46.158902+00:00 heroku[web.1]: State changed from starting to crashed
2016-11-04T09:07:48.965583+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=geeni-api.herokuapp.com request_id=0c8f07bb-0d78-4518-92b0-247baff498d6 fwd="24.130.184.126" dyno= connect= service= status=503 bytes=
2016-11-04T09:07:51.924182+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=geeni-api.herokuapp.com request_id=72547341-f293-4b7a-acbf-fb560b7e4827 fwd="24.130.184.126" dyno= connect= service= status=503 bytes=
2016-11-04T09:07:52.690127+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=geeni-api.herokuapp.com request_id=7fc5635a-4f8d-4922-b200-7158defebbf7 fwd="24.130.184.126" dyno= connect= service= status=503 bytes=

我的应用文件看起来像这样

geeniHeroku/
   ProcFile
   geeni.py
   requirements.txt

我做错了什么?我还完成了诸如 git init 之类的所有操作以及您需要执行的所有步骤。 我认为该错误与我的 ProcFile 内容有关 web gunicorn geeni:app

这是 requirements.txt 的内容

Flask==0.10.1
Flask_RESTful==0.2.12
itsdangerous==0.24
passlib==1.6.5
requests==2.11.1
stripe==1.27.1

【问题讨论】:

  • 日志中还有其他错误行吗?另外,你requirements.txt的内容是什么?
  • @DavidB。添加 requirements.txt 的内容
  • 正确,所以gunicorn 不在该文件中。如果加上相关版本呢?
  • 什么意思? gunicorn 是否需要在 requirements.txt 中?如果可以,可以举个例子吗?
  • 是的,正如devcenter.heroku.com/articles/python-gunicorn 中所述。所以你会添加一行:gunicorn==0.14.2(带有你要使用的 gunicorn 版本)

标签: python heroku flask


【解决方案1】:

将 gunicorn== 19.9.0 添加到 requirements.txt

【讨论】:

  • 请详细说明它的作用以及它回答问题的原因。
  • @JJJ 将python应用程序部署到heroku link 的主要要求之一
【解决方案2】:

尝试重启heroku:

heroku restart

如果不行,你可以尝试让heroku为你设置IP和端口,简单的用这个:
geeni.py

if __name__ == '__main__':
    app.run()

这里是a Flask template for Heroku

【讨论】:

  • 也许您可以尝试重新启动所有 dynos(在 heroku 仪表板中,单击 Open App 按钮旁边的 More 按钮)或在您的静态目录中添加一个网站图标(将其链接到您的 base.html )。
  • 我没有任何模板或静态文件夹。
  • 我已经尝试过你所说的所有事情。我仍然遇到错误 R10(启动超时)-> Web 进程在启动后 60 秒内无法绑定到 $PORT
【解决方案3】:

您正在设置自定义端口,在部署到 Heroku 时不应该这样做

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 2020-10-19
    • 2021-12-31
    相关资源
    最近更新 更多