簡體   English   中英

如何在 heroku 上使用 secrets.toml 部署 streamlit?

[英]how to deploy streamlit with secrets.toml on heroku?

您好,我有一個應用程序想部署在 heroku 上。 問題是我將如何使用 secrets.toml 部署一個 streamlit 應用程序?

目前可以通過此連接在本地完成

credentials = service_account.Credentials.from_service_account_info(
    st.secrets["gcp_service_account"])

但是,當我將它部署到 heroku 時,這似乎無法連接。

請幫忙。

在 heroku 上,我將 gcp_service_account 憑據作為配置變量輸入(從 heroku 儀表板轉到“設置”-->“顯示配置變量”,如下所示: heroku 配置變量

而不是st.secrets["<key>"] ,在你的 python 代碼中使用os.environ["<key>"]如下:

gsheet_url = os.environ['private_gsheets_url']

對於 gcp 服務帳戶憑據等嵌套機密,我首先解析 json 字符串,如下所示:

parsed_credentials = json.loads(os.environ["gcp_service_account"])
credentials = service_account.Credentials.from_service_account_info(parsed_credentials,scopes=scopes)

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM