Heroku:错误R10(引导超时)-> Web进程在启动后60秒内未能绑定到$ PORT-Python

时间:2018-08-25 19:56:02

标签: python heroku deployment bottle

我正在尝试托管一个使用tensorflow到heroku的瓶子应用程序,该应用程序启动,并且我也得到了“服务器在端口上运行” 。但该应用程序无法打开,大约一分钟后,它显示以下跟踪信息

打开跟踪说明服务器已成功运行,

2018-08-25T19:46:55.651043+00:00 heroku[web.1]: Starting process with command `python ./api.py -p 37040`
2018-08-25T19:47:01.379243+00:00 app[web.1]: Bottle v0.12.13 server starting up (using WSGIRefServer())...
2018-08-25T19:47:01.379274+00:00 app[web.1]: Listening on http://127.0.0.1:8080/
2018-08-25T19:47:01.379309+00:00 app[web.1]: Hit Ctrl-C to quit.
2018-08-25T19:47:01.379318+00:00 app[web.1]:undefined

几分钟后。错误跟踪。

2018-08-25T19:47:56.239318+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-08-25T19:47:56.239392+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-08-25T19:47:56.330436+00:00 heroku[web.1]: Process exited with status 137
2018-08-25T19:47:56.353021+00:00 heroku[web.1]: State changed from starting to crashed
2018-08-25T19:47:59.452460+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-forest-70642.herokuapp.com request_id=8b62b91c-8f22-4c37-b3c5-cbc7e8415e3d fwd="123.231.104.11" dyno= connect= service= status=503 bytes= protocol=https
2018-08-25T19:47:59.500660+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/robots.txt" host=boiling-forest-70642.herokuapp.com request_id=e8860f29-40fd-46b1-b9f2-96683f53d524 fwd="123.231.104.11" dyno= connect= service= status=503 bytes= protocol=https
2018-08-25T19:48:02.118233+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=boiling-forest-70642.herokuapp.com request_id=1f9aafbe-f410-46ab-84ed-41bbc90857e6 fwd="123.231.104.11" dyno= connect= service= status=503 bytes= protocol=https

我不知道自己做错了什么,因为我是Heroku或瓶子的新手。

procfile:

web: python ./api.py -p $PORT

api.py文件

@get('/')
def get_top_predictions():
    #lable_index, labels_list, results_list = li.get_lables("bottle.jpg")
    #selected_list = [{"class": labels_list[i], "probability": float(results_list[i]) } for i in lable_index]
    #return {"predictions": selected_list}
    return {"predictions": "Hello Man"}

run()

我还尝试了设置run(host='0.0.0.0')之类的选项。仍然无法正常工作并给出相同的错误消息。

有人可以告诉我这是怎么回事吗?

1 个答案:

答案 0 :(得分:1)

您的应用程序需要绑定到外部可见地址上的Heroku提供的端口。您有两种成分,只是没有正确地混合在一起。您尝试过run(host='0.0.0.0'),并且在Procfile中包含了-p $PORT,但是没有显示指示如何使用它的代码。

尝试以下方法:

run(host='0.0.0.0', port=os.environ.get('PORT', '5000'))