Longitude and latitude in secrets.toml file

I am trying to add a weather widget in my streamlit app. I stored my API_KEY, longitude and latitude values in the secrets.toml file. My latitude value is a negative value, I used inverted commas for example lat = “-30.55445” in my secrets.toml file. It ran fine when I ran it on localhost for a while, now it doesn’t. It gives me this error: KeyError: 'st.secrets has no key “lat”. Did you forget to add it to secrets.toml or the app settings on Streamlit Cloud? I really don’t know what I could be doing wrong, because my app is down now, because of this error.

These are example of my secrets.toml file:

[my_secrets]
API_KEY = '15654684sd4f64sg64g6a4gd89g4ad8'
latitude="-30.55445" 
longitude="55.3336"

Someone please help.

The error does not match with the code snippet. By the way, do not past code as image…

I changed lat to latitude to see if it would change anything, it didn’t.

I guess you point your code to the my_secrets key, something like st.secrets.my_secrets.latitude

I tried your suggestion, it ran fine on localhost. When I deployed it, I received this error:
Traceback (most recent call last):
File “/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 565, in _run_script
exec(code, module.dict)
File “/app/lesson-planafr/app.py”, line 111, in
latitude = st.secrets.my_secrets.latitude
File “/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/secrets.py”, line 296, in getattr
raise AttributeError(_missing_attr_error_message(key))
AttributeError: st.secrets has no attribute “my_secrets”. Did you forget to add it to secrets.toml or the app settings on Streamlit Cloud? More info: Secrets management - Streamlit Docs

That is expected behavior. Read Secrets management - Streamlit Docs for more info.

What part is expected behavior? I used these instructions you gave me to develop my code. Looking out for these expected errors. So, can you tell me what part was expected behavior?

It looks like I had to create a new repo and also a new app before it could deploy successfully.

My plan was to update my existing app with a new weather widget which contained an API key as everybody knows. Now adding a secrets.toml file and adding it to a .gitignore file doesn’t deploy your app successfully.

My suggestion is that the Streamlit developers should look into this, because as a result I had to create an entirely new app with a new link just to add a widget to my app, which isn’t ideal.

Thanks to all the inputs you guys gave me.

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