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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.