UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Hi there everyone!

I’m new to this forum, although I’ve been using Streamlit for 3 months or so. I’ve run into a problem that I don’t know how to solve. I’ve been working in a streamlit app that before yesterday worked just fine. Somehow, it doesn’t work anymore and I’m not conscious of having done anything that could alter its behaviour.

The error is this one:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

So I surfed on the internet reading why this happens and there are a lot of topics related to csv files and so on. I read separately each of the csv files and excel files that my app uses and the problem isn’t there.

Then I created a dumb app that consists in this two lines of code with the only purpose of executing a streamlit app to see if the error was there:

import streamlit as st

st.write("Hi there!")

And the error that I got is exactly the same:

Traceback (most recent call last):
  File "C:/Users/alons/PycharmProjects/maps5/prueba2.py", line 3, in <module>
    st.write("Hi there!")
  File "C:\Users\anaconda3\envs\maps5\lib\site-packages\streamlit\elements\write.py", line 234, in write
    flush_buffer()
  File "C:\Users\anaconda3\envs\maps5\lib\site-packages\streamlit\elements\write.py", line 168, in flush_buffer
    self.dg.markdown(
  File "C:\Users\anaconda3\envs\maps5\lib\site-packages\streamlit\elements\markdown.py", line 79, in markdown
    return self.dg._enqueue("markdown", markdown_proto)
  File "C:\Users\anaconda3\envs\maps5\lib\site-packages\streamlit\delta_generator.py", line 376, in _enqueue
    st._maybe_print_use_warning()
  File "C:\Users\anaconda3\envs\maps5\lib\site-packages\streamlit\__init__.py", line 466, in _maybe_print_use_warning
    elif not _is_running_with_streamlit and _config.get_option(
  File "C:\Users\anaconda3\envs\maps5\lib\site-packages\streamlit\config.py", line 103, in get_option
    config_options = get_config_options()
  File "C:\Users\anaconda3\envs\maps5\lib\site-packages\streamlit\config.py", line 1096, in get_config_options
    file_contents = input.read()
  File "C:\Users\anaconda3\envs\maps5\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

If I run “Streamlit hello” on the terminal, once more I get the same error.

I don’t know why this happens, everything worked just fine until yesterday.

Streamlit version when I encountered this error: I think 1.4, then upgraded to 1.7 (didn’t work) then downgraded to 1.2 (didn’t work).
I’m using a conda environment and python version 3.9.0 in a Windows machine.

Thanks in advance!

Hi @Alonso -

I would check what codec your text editor is set to save files as. I suspect the issue, since you are using a Windows computer, is that the source Python file is being set to something other than UTF-8. Switch that encoding and try again and see if that fixes your issue.

Best,
Randy

Hi @randyzwitch, thanks for yor answer!

I’m using pycharm as code editor and my configuration was this one:

I changed that windows-1252 to UTF-8 and that ISO-8859-1 to UTF-8 as well. Saved my files, reinitiated pycharm and it doesn’t work.

What surprises me is that it seems some problem related to Streamlit, because I can run other files, but not the ones that make use of Streamlit.

Thanks again!

I am pretty sure that this issue is not related to streamlit in any way.
Please check your file encoding with a different editor (VSCode, Notepad++ …)

2 Likes

Hi, in the case of streamlit it’s a matter of configuring your folder, something you’ll have to do manually.
You go to that streamlit folder and delete the files inside it,
image
normally there are 3 configuration files, after that I recommend you to uninstall the library close the terminal, install again.

1 Like

Wow thanks, that worked!

Thank you very much!