简体   繁体   中英

Heroku Application Error python flask

I'm trying to make production ready. Have my own domain in future and make calls for stripe. However I'm having issue deploying my app.

'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)

Under my ProcFile I have following stuff

"web gunicorn geeni:app"

So I call

heroku ps:scale web=1

Instantly throws me this error:

    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=

My app file looks something like this

geeniHeroku/
   ProcFile
   geeni.py
   requirements.txt

What am I doing wrong? I've also done everything such as git init and all the steps you are required to do. I think the error has to do with my ProcFile content web gunicorn geeni:app

Here's the contents of 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

将 gunicorn== 19.9.0 添加到 requirements.txt

Try to restart heroku:

heroku restart

If it isn't work, you can try to let heroku to set the IP and port for you, simplely use this:
geeni.py

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

And here is a Flask template for Heroku .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM