My intention is to copy and paste a dictionary with JSON credentials but to simplify the problem I don’t know how to assign dictionaries to a variable in secrets.toml if it is possible.
Steps to reproduce
Code snippet:
add code here
.streamlit/secrets.toml
this_var = {‘a key’: ‘a value’}
Expected behavior:
You should simply assign a dictionary for use in the app.
Actual behavior:
The system displays a parse error.
Thanks for responding so quickly. If you define a section with [this_var] it does work but the Python dictionary-like option with
this_var = { ‘a key’ = ‘a value’ }
shows the following error.
KeyError: ‘st.secrets has no key “type”. Did you forget to add it to secrets.toml or the app settings on Streamlit Cloud? More info: Secrets management - Streamlit Docs’
You are right. I have created a new app just with the code you have written and it works correctly.
Doing some more tests I found the error. If the entry line in secrets.toml of the dictionary has more than one line it causes the error. That is to say,
this_var2 produces the error. Of course, having the assignments delimited by braces {} to define the dictionary structure I understood that the line endings were ignored, but it seems that this is not the case.
Inline tables are intended to appear on a single line. A terminating comma (also called trailing comma) is not permitted after the last key/value pair in an inline table. No newlines are allowed between the curly braces unless they are valid within a value. Even so, it is strongly discouraged to break an inline table onto multiples lines.