首页 > 解决方案 > 在 Heroku 上使用 streamlit 部署错误 python 应用程序

问题描述

我正在尝试在 Heroku 上部署一个应用程序,我遵循了网络上的大多数指南。在本地我的应用程序工作正常,但是当我尝试部署它时,我收到状态码 132 的错误。

我的应用要求是

streamlit==0.73.1
tensorflow-cpu==2.4.0
numpy==1.19.4
Keras==2.4.3
Pillow==8.0.1

我的过程文件是

web: sh setup.sh && streamlit run app.py

我的 setup.sh 文件是

mkdir -p ~/.streamlit/

echo "
[server]
headless = true
enableCORS=false
port = $PORT
" > ~/.streamlit/config.toml

部署后的日志如下:

2021-01-02T15:01:36.690121+00:00 heroku[web.1]: Starting process with command `sh setup.sh && streamlit run app.py` 2021-01-02T15:01:39.309566+00:00 app[web.1]: 2021-01-02 15:01:39.309 2021-01-02T15:01:39.309579+00:00 app[web.1]: Warning: the config option 'server.enableCORS=false' is not compatible with 'server.enableXsrfProtection=true'. 2021-01-02T15:01:39.309580+00:00 app[web.1]: As a result, 'server.enableCORS' is being overridden to 'true'. 2021-01-02T15:01:39.309580+00:00 app[web.1]: 2021-01-02T15:01:39.309580+00:00 app[web.1]: More information: 2021-01-02T15:01:39.309584+00:00 app[web.1]: In order to protect against CSRF attacks, we send a cookie with each request. 2021-01-02T15:01:39.309584+00:00 app[web.1]: To do so, we must specify allowable origins, which places a restriction on 2021-01-02T15:01:39.309584+00:00 app[web.1]: cross-origin resource sharing. 2021-01-02T15:01:39.309584+00:00 app[web.1]: 2021-01-02T15:01:39.309585+00:00 app[web.1]: If cross origin resource sharing is required, please disable server.enableXsrfProtection. 2021-01-02T15:01:39.309585+00:00 app[web.1]: 2021-01-02T15:01:40.780708+00:00 app[web.1]: 2021-01-02 15:01:40.780 2021-01-02T15:01:40.780724+00:00 app[web.1]: Warning: the config option 'server.enableCORS=false' is not compatible with 'server.enableXsrfProtection=true'. 2021-01-02T15:01:40.780726+00:00 app[web.1]: As a result, 'server.enableCORS' is being overridden to 'true'. 2021-01-02T15:01:40.780727+00:00 app[web.1]: 2021-01-02T15:01:40.780727+00:00 app[web.1]: More information: 2021-01-02T15:01:40.780729+00:00 app[web.1]: In order to protect against CSRF attacks, we send a cookie with each request. 2021-01-02T15:01:40.780729+00:00 app[web.1]: To do so, we must specify allowable origins, which places a restriction on 2021-01-02T15:01:40.780729+00:00 app[web.1]: cross-origin resource sharing. 2021-01-02T15:01:40.780730+00:00 app[web.1]: 2021-01-02T15:01:40.780731+00:00 app[web.1]: If cross origin resource sharing is required, please disable server.enableXsrfProtection. 2021-01-02T15:01:40.780808+00:00 app[web.1]: 2021-01-02T15:01:40.911074+00:00 heroku[web.1]: State changed from starting to up 2021-01-02T15:01:41.230942+00:00 heroku[web.1]: Process exited with status 132 2021-01-02T15:01:41.270167+00:00 heroku[web.1]: State changed from up to crashed 2021-01-02T15:01:41.273580+00:00 heroku[web.1]: State changed from crashed to starting 2021-01-02T15:02:08.401555+00:00 heroku[web.1]: Starting process with command `sh setup.sh && streamlit run app.py` 2021-01-02T15:02:11.419271+00:00 app[web.1]: 2021-01-02 15:02:11.419 2021-01-02T15:02:11.419308+00:00 app[web.1]: Warning: the config option 'server.enableCORS=false' is not compatible with 'server.enableXsrfProtection=true'. 2021-01-02T15:02:11.419309+00:00 app[web.1]: As a result, 'server.enableCORS' is being overridden to 'true'. 2021-01-02T15:02:11.419309+00:00 app[web.1]: 2021-01-02T15:02:11.419309+00:00 app[web.1]: More information: 2021-01-02T15:02:11.419310+00:00 app[web.1]: In order to protect against CSRF attacks, we send a cookie with each request. 2021-01-02T15:02:11.419310+00:00 app[web.1]: To do so, we must specify allowable origins, which places a restriction on 2021-01-02T15:02:11.419310+00:00 app[web.1]: cross-origin resource sharing. 2021-01-02T15:02:11.419311+00:00 app[web.1]: 2021-01-02T15:02:11.419311+00:00 app[web.1]: If cross origin resource sharing is required, please disable server.enableXsrfProtection. 2021-01-02T15:02:11.419317+00:00 app[web.1]: 2021-01-02T15:02:12.914113+00:00 app[web.1]: 2021-01-02 15:02:12.913 2021-01-02T15:02:12.914164+00:00 app[web.1]: Warning: the config option 'server.enableCORS=false' is not compatible with 'server.enableXsrfProtection=true'. 2021-01-02T15:02:12.914166+00:00 app[web.1]: As a result, 'server.enableCORS' is being overridden to 'true'. 2021-01-02T15:02:12.914167+00:00 app[web.1]: 2021-01-02T15:02:12.914167+00:00 app[web.1]: More information: 2021-01-02T15:02:12.914168+00:00 app[web.1]: In order to protect against CSRF attacks, we send a cookie with each request. 2021-01-02T15:02:12.914169+00:00 app[web.1]: To do so, we must specify allowable origins, which places a restriction on 2021-01-02T15:02:12.914169+00:00 app[web.1]: cross-origin resource sharing. 2021-01-02T15:02:12.914169+00:00 app[web.1]: 2021-01-02T15:02:12.914170+00:00 app[web.1]: If cross origin resource sharing is required, please disable server.enableXsrfProtection. 2021-01-02T15:02:12.914178+00:00 app[web.1]: 2021-01-02T15:02:13.021459+00:00 app[web.1]: 2021-01-02T15:02:13.026687+00:00 app[web.1]: You can now view your Streamlit app in your browser. 2021-01-02T15:02:13.029934+00:00 app[web.1]: 2021-01-02T15:02:13.030174+00:00 app[web.1]: Network URL: http://172.17.33.114:49762 2021-01-02T15:02:13.030336+00:00 app[web.1]: External URL: http://54.196.74.62:49762 2021-01-02T15:02:13.030463+00:00 app[web.1]: 2021-01-02T15:02:13.230184+00:00 heroku[web.1]: Process exited with status 132 2021-01-02T15:02:13.296289+00:00 heroku[web.1]: State changed from starting to crashed 2021-01-02T15:02:18.000000+00:00 app[api]: Build succeeded 2021-01-02T15:13:20.200097+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=bee-vs-wasp.herokuapp.com request_id=33a0b7a9-06da-4a29-aa2d-38f06fed7a58 fwd="93.34.114.71" dyno= connect= service= status=503 bytes= protocol=http 2021-01-02T15:13:20.786124+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=bee-vs-wasp.herokuapp.com request_id=8cdca19c-aacc-477d-a979-5628ed62989d fwd="93.34.114.71" dyno= connect= service= status=503 bytes= protocol=http 2021-01-02T15:13:21.850425+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=bee-vs-wasp.herokuapp.com request_id=4831ca5f-2e87-46b0-bdbc-d98ca5352310 fwd="93.34.114.71" dyno= connect= service= status=503 bytes= protocol=http

标签: pythonherokustreamlit

解决方案


推荐阅读