Secrets.toml not Found

Secrets file not found. Expected at: C:\Users\enes_\Desktop\Projects\Commi Atılacak\Garbage-Management-at-Istanbul.streamlit\secrets.toml

FileNotFoundError: [Errno 2] No such file or directory: ‘C:\Users\enes_\Desktop\Projects\Commi Atılacak\Garbage-Management-at-Istanbul\.streamlit\secrets.toml’

I tried to add secrets.toml to the main file that I’m working and I created a streamlit file and added the tml file inside it but both of them didn’t work.

I’m trying to add a comment section to my app using this repo.

Can anyone help me who used this kinda thing before?

Did you make sure to name your folder .streamlit with a dot at the beginning, and then put the secrets.toml file inside of that folder?

The file structure should then be:

  • app.py
  • .streamlit/
    • secrets.toml
1 Like

@st.experimental_singleton()
def connect():
# Create a connection object.
credentials = service_account.Credentials.from_service_account_info(
st.secrets[“gcp_service_account”],
scopes=[SCOPE],
)
at repo there is a db.py file in there there is a few code lines like that. Do anyone knows what should I text for gcp_service_account

It should look something like this (in toml format)

[gcp_service_account]

type = "service_account"
project_id = "PROJECT_ID"
private_key_id = "KEY_ID"
private_key = "-----BEGIN PRIVATE KEY-----\nPRIVATE_KEY\n-----END PRIVATE KEY-----"
client_email = "SERVICE_ACCOUNT_EMAIL"
client_id = "CLIENT_ID"
auth_uri = "https://accounts.google.com/o/oauth2/auth"
token_uri = "https://accounts.google.com/o/oauth2/token"
auth_provider_x509_cert_url = "https://www.googleapis.com/oauth2/v1/certs"
client_x509_cert_url = "https://www.googleapis.com/robot/v1/metadata/x509/SERVICE_ACCOUNT_EMAIL"

You can see more info about creating and using those credentials here Create and manage service account keys  |  IAM Documentation  |  Google Cloud


I did a .toml file like you sent and read value from that.

But I got the following error from that:

SPREADSHEET_ID=“1em4x3cE0R22mCwcNTQxhN4lblhGQkq9O_D48REQ8g1M”
SAMPLE_RANGE_NAME = ‘StreamlitGarbage!A1:C1’

def collect(gsheet_connector) → pd.DataFrame:
values = (
gsheet_connector.values()
.get(
spreadsheetId=SPREADSHEET_ID,
range=SAMPLE_RANGE_NAME,
)
.execute()
)

df = pd.DataFrame(values["values"])
df.columns = df.iloc[0]
df = df[1:]
return df

Do you have a worksheet titled StreamltiGarbage in that google sheet? If you only have one worksheet, you could just use A1:C1, with the worksheet name.

For what it’s worth, I find https://docs.gspread.org/ to be a much more pleasant usage experience rather than using the official Google Google Sheets API directly.

Thanks for your answers. They were great !

1 Like

Hi Blackary e.a.
for me the .streamlit folder is directly under my home directory (Windows). But please note that the backslash before .streamlit is missing in this message, therefore I assume this is a bug in streamlit at creation of the path using the home directory.

Repro:
I put my secrets.toml into exactly the same folder where config.toml is located, which makes effective changes to the appearance, so the folder is functional to Streamlit.

Symptom:
there is a folder path error indicated in the message where the backslash after my home directory is not inserted into the path.

Message
Secrets file not found.

Expected at: C:\Users\AGW.streamlit\secrets.toml

Bug:
the message is showing a path that is not correctly composed. It should contain a backslash.

Trace:
FileNotFoundError: [Errno 2] No such file or directory: ‘C:\Users\AGW\.streamlit\secrets.toml’

Traceback:

File "C:\Users\AGW\Anaconda3\envs\stenv\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
    exec(code, module.__dict__)File "C:\Users\AGW\GIT\testItOut\streamlit_app.py", line 5, in <module>
    st.write(st.secrets['message'])File "C:\Users\AGW\Anaconda3\envs\stenv\lib\site-packages\streamlit\runtime\secrets.py", line 267, in __getitem__
    value = self._parse(True)[key]File "C:\Users\AGW\Anaconda3\envs\stenv\lib\site-packages\streamlit\runtime\secrets.py", line 174, in _parse
    with open(self._file_path, encoding="utf-8") as f:

Hi @ansgargw, I suspect the missing backslash is simply a visual error in the error message, since the Trace shows the backlash there. Can you try putting your secrets in the C:\Users\AGW\GIT\testItOut\ directory instead?

e.g.

C:\Users\AGW\GIT\testItOut\.streamlit\secrets.toml

I’m not sure if streamlit is supposed to work with a global secrets file in your home directly, but it definitely should work with a folder in your repo, as noted in the docs Secrets management - Streamlit Docs