Toml decoder error (TomlDecodeError)

As of this evening, I cannot do anything with streamlit, not even run the streamlit hello or even streamlit version. The only thing I can think of that chagned was commiting my code to a new GitHub repository. The error I get is:

(base) C:\Users\Erik\Desktop>streamlit hello
Traceback (most recent call last):
  File "c:\users\erik\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\erik\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Erik\Anaconda3\Scripts\streamlit.exe\__main__.py", line 5, in <module>
  File "c:\users\erik\anaconda3\lib\site-packages\streamlit\cli.py", line 34, in <module>
    import streamlit.bootstrap as bootstrap
  File "c:\users\erik\anaconda3\lib\site-packages\streamlit\bootstrap.py", line 30, in <module>
    from streamlit.server.Server import Server
  File "c:\users\erik\anaconda3\lib\site-packages\streamlit\server\Server.py", line 36, in <module>
    from streamlit.ReportSession import ReportSession
  File "c:\users\erik\anaconda3\lib\site-packages\streamlit\ReportSession.py", line 42, in <module>
    from streamlit.watcher.LocalSourcesWatcher import LocalSourcesWatcher
  File "c:\users\erik\anaconda3\lib\site-packages\streamlit\watcher\LocalSourcesWatcher.py", line 79, in <module>
    FileWatcher = get_file_watcher_class()
  File "c:\users\erik\anaconda3\lib\site-packages\streamlit\watcher\LocalSourcesWatcher.py", line 60, in get_file_watcher_class
    watcher_type = config.get_option("server.fileWatcherType")
  File "c:\users\erik\anaconda3\lib\site-packages\streamlit\config.py", line 95, in get_option
    parse_config_file()
  File "c:\users\erik\anaconda3\lib\site-packages\streamlit\config.py", line 852, in parse_config_file
    _update_config_with_toml(file_contents, filename)
  File "c:\users\erik\anaconda3\lib\site-packages\streamlit\config.py", line 774, in _update_config_with_toml
    parsed_config_file = toml.loads(raw_toml)
  File "c:\users\erik\anaconda3\lib\site-packages\toml\decoder.py", line 379, in loads
    original, pos)
toml.decoder.TomlDecodeError: Key group not on a line by itself. (line 1 column 1 char 0)

Seems like an issue with the toml decoder.

I have uninstalled, reinstalled, upgraded and downgraded to 0.37. Nothing works.

Thoughts?

2 Likes

FIXED:

I found the config file at ~/.streamlit.config.toml and deleted the contents. Not sure how/when the config file got set up incorrectly.

The contents of that file (all were on one line) are below

[server]\nheadless = true\nenableCORS=false\nport = \n

Would still be interested to know if this is a bug or something I messed up somehow.

7 Likes

Hey @eriktuck,

Yes it looks like the problem that you were having was the malformed config file. It shouldn’t be a single line file.

Let us know if you have another question.

Could you point me out the location of the ~/.streamlit.config.toml file? I can’t seem to find it unfortunately and I’m having the same error.

2 Likes

Having the same problem here and also unsure about the location of the config.toml file.

I found the .config.toml file in my User Directory (at C:/Users/Erik/.streamlit/config.toml). I originally searched the C:/ drive for .toml files and found it that way. Hope this helps.

7 Likes

Yes found it and it solved the issue. Thanks!

Glad it worked out.

Just a note for others, if you’re on a Windows system dot files/folders (like .streamlit/) may be hidden by default. You’ll have to change that to see this file in your directory.

1 Like

Hi @eriktuck,

Quick question, are you seeing the file at C:/Users/Erik/.streamlit.config.toml or at C:/Users/Erik/.streamlit/config.toml?

Also did you create this file manually?

1 Like

Right. I found the file at C:/Users/Erik/.streamlit/config.toml. Typo on my part.

I was able to recreate the error. I am deploying my app to Heroku. I have a setup.sh file. If I run the setup.sh file outside of the Heroku environment (e.g., double click the file on my computer), it populates the config.toml file with the single line. The setup.sh file contents are pasted below, so you can see how this is happening. I’m running Windows 8.1 locally.

mkdir -p ~/.streamlit/

echo "\
[general]\n\
email = \"your-email@domain.com\"\n\
" > ~/.streamlit/credentials.toml

echo "\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml
3 Likes

Hi Erik
I am having similar issue and couldn’t find the config file. I am using MacBook. I can see the streamlit folder but no config.toml file.

Welcome to the forum @KIRTISNIGDHA :wave: ,

This thread might help answer your question. Feel free to let us know if you need any additional help!

1 Like

Hey Erik,
I did find the config.toml file but how do I edit it now, as in where can I find the appropriate content of the file?

I deleted the file entirely. You might, to be safe, simply move it to a different directory and/or change the name of the file. But, for me, deleting it solved the problem.

2 Likes

Many thanks!

Deleting Credentials.toml and Config.toml resolves my problem

2 Likes

I found I had this issue on Windows 10 when I ran:

streamlit config show > ~/.streamlit/config.toml

For example, with no config.toml file I run:

streamlit hello

And I am greeted with:

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://192.168.100.75:8501

I then run:

streamlit config show > ~/.streamlit/config.toml

And then running streamlit hello I am greeted with:

PS C:\Users\sbiggs> streamlit config show > ~/.streamlit/config.toml
PS C:\Users\sbiggs> streamlit hello
Traceback (most recent call last):
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\sbiggs\AppData\Local\Continuum\anaconda3\Scripts\streamlit.exe\__main__.py", line 4, in <module>
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\__init__.py", line 103, in <module>
    from streamlit.DeltaGenerator import DeltaGenerator as _DeltaGenerator
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\DeltaGenerator.py", line 27, in <module>
    from streamlit import caching
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\caching.py", line 40, in <module>
    from streamlit.hashing import Context
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\hashing.py", line 41, in <module>
    from streamlit.folder_black_list import FolderBlackList
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\folder_black_list.py", line 39, in <module>
    if config.get_option("global.developmentMode"):
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\config.py", line 90, in get_option
    parse_config_file()
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\config.py", line 888, in parse_config_file
    _update_config_with_toml(file_contents, filename)
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\site-packages\streamlit\config.py", line 810, in _update_config_with_toml
    parsed_config_file = toml.loads(raw_toml)
  File "c:\users\sbiggs\appdata\local\continuum\anaconda3\lib\site-packages\toml\decoder.py", line 227, in loads
    original, i)
toml.decoder.TomlDecodeError: Found invalid character in key name: '#'. Try quoting the key name. (line 1 column 3 char 2)

The only way I have found to fix it, is to completely delete the file, and then write it a fresh.

Thanks Erik! this was key to solve the problem.

1 Like

Thank you so much! You helped solved it! I was struggling with this since 8 hours. I was deploying apps to heroku and idk what changed. It was working and then suddenly it stopped working!

1 Like

For Mac Users,

I came across this error while trying to deploy my app using Heroku.
so one way to solve this is by removing the config.toml file completely as most of the comments in the comment section suggest. Don’t worry about finding the config.toml file if you are planning to just delete it.

just open terminal execute these commands -

  1. streamlit config show > ~/.streamlit/config.toml
  2. rm -i ~/.streamlit/config.toml

what this will do is completly remove the config.toml file

next, test it using the command streamlit hello and things should be back to normal.

2 Likes