How to solve this: toml.decoder.TomlDecodeError?

Hello everyone, everything good? The code is working, but I don’t understand why it is giving the following error. Before deploying I want to resolve this error.

2023-03-23 21:52:00.488 Failed to load secrets.toml file
Traceback (most recent call last):
  File "C:\Users\wagne\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\web\bootstrap.py", line 174, in _on_server_start
    secrets.load_if_toml_exists()
  File "C:\Users\wagne\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\runtime\secrets.py", line 128, in load_if_toml_exists
    self._parse(print_exceptions=False)
  File "C:\Users\wagne\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\runtime\secrets.py", line 182, in _parse
    secrets = toml.loads(secrets_file_str)
  File "C:\Users\wagne\AppData\Local\Programs\Python\Python310\lib\site-packages\toml\decoder.py", line 260, in loads
    raise TomlDecodeError("Found invalid character in key name: '" +
toml.decoder.TomlDecodeError: Found invalid character in key name: ':'. Try quoting the key name. (line 6 column 7 char 181)

I’m turning a google spreadsheet into a dataframe, and after that I’m creating some charts with the data from the spreadsheet. For this I am using gspread as follows.

gc = gspread.oauth()
sh = gc.open("spreadsheet_name")
page = sh.worksheet('sheet1')
df = pd.DataFrame(page.get_all_records())

Could someone help me to resolve this error?

The re seems to be a corrupted secrets.toml file somewhere. Locate it and fix or delete it.

I faced the same error. I had copied the JSON file I got from Google cloud console and pasted it in the secrets.toml file, and was facing this issue. After much head scratching, it seems you just need to replace the : in each line with an =. Also, make sure to remove the comma at the end of each line, cause that’s gonna cause another issue if you copied the JSON file like I did.

So, instead of -

type: "service_account",

It would be

type = "service_account"

Do this for each line. The issue should be fixed.

1 Like

I got the error parsing secrets file TomlDecodeError: Reserved escape sequence used.

and I am trying to connect the Streamlit app to MS SQL Server.

Problem solved by using escape character () in Server name like below in secrets.toml file

server = “CT\SQLSERVER2019”

where is CT is my Computer’s name.