【问题标题】:how to deploy streamlit with secrets.toml on heroku?如何在 heroku 上使用 secrets.toml 部署 streamlit?
【发布时间】:2022-12-13 22:41:02
【问题描述】:

您好,我有一个应用程序想部署在 heroku 上。问题是我将如何使用 secrets.toml 部署一个 streamlit 应用程序?

目前可以通过此连接在本地完成

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

但是,当我将它部署到 heroku 时,这似乎无法连接。

请帮忙。

【问题讨论】:

    标签: python heroku streamlit


    【解决方案1】:

    在 heroku 上,我将 gcp_service_account 凭据作为配置变量输入(从 heroku 仪表板转到“设置”-->“显示配置变量”,如下所示:

    在您的 Python 代码中使用 os.environ["<key>"] 而不是 st.secrets["<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)
    

    希望这可以帮助。

    【讨论】:

      猜你喜欢
      • 2021-08-01
      • 2020-11-08
      • 2020-11-10
      • 2023-02-14
      • 2020-03-21
      • 2020-11-21
      • 2013-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多