Followed 3 other secrets implementations in the forum but cannot get it to work

1.Running app locally

  1. Deployed: wqureshi.streamlit.app
  2. Deployed on Community Cloud
  3. wqureshi.streamlit.app
  4. GitHub: Repository
  5. Error message:
Traceback (most recent call last):
  File "c:\Users\Waqar Qureshi\Desktop\Python Projects\stock_market_assessment\.streamlit\scratch_paper.py", line 3, in <module>
    api = st.secrets("fred_API_key")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'Secrets' object is not callable

Folder structure of where I keep my secrets.toml file + the contents of my secrets.toml file:

How I am calling and trying to retrieve the secrets:

import streamlit as st

api = st.secrets("fred_API_key")

print(api)

I figured it. It’s odd but I was able to access the API Key by using the attribute notation instead of the key notation.

What worked:

api = st.secrets.fred_API_key

What didn’t work:

api = st.secrets("fred_API_key")

Key notation would be api = st.secrets["fred_API_key"]. See the examples in the documentation.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.