Version 0.64.0 • Deprecation warning for st.file_uploader decoding

Version 0.64.0

Highlights:

  • :bar_chart: Default matplotlib to display charts with a tight layout. To disable this,
    set bbox_inches to None, inches as a string, or a Bbox.
  • :desktop_computer: Allow fullscreen content for Streamlit Components.
  • :card_file_box: Deprecation warning for automatic decoding on st.file_uploader.
  • :see_no_evil: If gatherUserStats is False, do not even load the Segment library.
    Thanks @tanmaylaud!

Deprecation Warning: FileUploader will no longer decode files automatically beginning after August 15th.

After the initial release of the file uploader, we’ve had great feedback from the community and are undergoing a redesign. Because there is no reliable way for us to decode files with 100% accuracy, we’ve decided to separate any decoding from the file uploader API. This means that all files will be returned as a binary buffer beginning August 15th.

What can I do?

After August 15th, 2020, your application may break depending on the type of file processing being performed. We recommend taking action now to prevent any errors once the redesigned file uploader comes out.

If you are expecting a text buffer, we recommend wrapping your returned buffer in a TextIOWrapper. This will work today, and will continue to work once the file uploader API changes. To learn more about TextIOWrapper check out the python documentation.

Current:

import io
import streamlit as st

maybe_string_io = st.file_uploader(...)
# Today, maybe_string_io is either a StringIO or a BytesIO
# depending on the uploaded file.

Recommendation:

import io
import streamlit as st

uploaded_file = st.file_uploader(...)
text_io = io.TextIOWrapper(uploaded_file)

If you are expecting uploading binary files, no action is necessary.

What if I don’t do anything?

As part of this release, st.file_uploader will now display a deprecation warning if you provide an encoding or relying on our default auto encoding. This warning can be disabled with the deprecation.showfileUploaderEncoding config option.

st.set_option('deprecation.showfileUploaderEncoding', False)

or in your .streamlit/config.toml

[deprecation]
showfileUploaderEncoding = False
1 Like

Hi,
I tried to upgrade my streamlit installation (0.62.0) with the command:
pip install --upgrade streamlit.
All ok but when I run one of miy application there is an issue.
I also tried the following command: streamlit config show but there is the same issue.
Then I uninstalled and reinstalled the same version (0.64.0), but nothing has changed.
So I uninstalled the version 0.64.0 and installed the version 0.62.1.
And so everything went back to work.
I apologize for not copying the trace
Tomorrow I’ll do the operation again and copy the error.

Any ideas on how to proceed to solve the issue?

Which issue is that?
if its what i think it is try
pip3 install --upgrade protobuf

3 Likes

Hi @amitg1
This is the traceback:

Traceback (most recent call last):
  File "c:\users\mauro_s1nn2ps\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\mauro_s1nn2ps\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\mauro_s1nn2ps\AppData\Local\Programs\Python\Python37\Scripts\streamlit.exe\__main__.py", line 4, in <module>
  File "c:\users\mauro_s1nn2ps\appdata\local\programs\python\python37\lib\site-packages\streamlit\__init__.py", line 102, in <module>
    from streamlit.DeltaGenerator import DeltaGenerator as _DeltaGenerator
  File "c:\users\mauro_s1nn2ps\appdata\local\programs\python\python37\lib\site-packages\streamlit\DeltaGenerator.py", line 41, in <module>
    from streamlit.proto import Alert_pb2
  File "c:\users\mauro_s1nn2ps\appdata\local\programs\python\python37\lib\site-packages\streamlit\proto\Alert_pb2.py", line 21, in <module>
    create_key=_descriptor._internal_create_key,
AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key'

I see in traceback “protobuf”. You are probably right.
Now I try to upgrade protobuf

Ok, with upgrade protobuf, streamlit 0.64.0 works!

Thanks @amitg1

@karriebear could you elaborate a bit more on this? This doesn’t work for me.
I upload a yaml file and the file_uploader returns as of today a io.StringIO, which is fine for me. But when I wrap that inside a io.TextIOWrapper it breaks my application, because io.TextIOWrapper expects an io.BytesIO instance. So as I understand it, as long as I get a io.StringIO from the file_uploader, I can’t really ‘futureproof’ my application.

Hi @wAuner, thank you for the find! Apologies for the faulty recommendation :frowning: It looks like the best way to futureproof will be to add a conditional statement to wrap into a TextIOWrapper if it is a BytesIO.

uploaded_file = st.file_uploader(...)
if isinstance(uploaded_file, io.BytesIO):
    text_io = io.TextIOWrapper(uploaded_file)

Hope this helps!

Hi @karriebear, using your code still shows a FileUploaderEncodingWarning warning message!

That’s correct. The code snippet is if you would like to update your app now so that things will not break once the new file uploader is released.

If you’d like to disable the warning, please disable the deprecation message.
st.set_option('deprecation.showfileUploaderEncoding', False)

Hey @karriebear, I’m using heroku platform to deploy my streamlit app.
But st.set_option('deprecation.showfileUploaderEncoding', False) is giving me error. Please help.

1 Like

I am also having the same issue when deploying with Heroku… Anyone can help here? Thanks

@SiddhanthNB: Were you able to find a solution?. In my case the following happens:

  • Before deploying to Heroku it works fine with st.set_option(‘deprecation.showfileUploaderEncoding’, False)
  • But when I have deployed I received the following error: KeyError: ‘deprecation.showfileUploaderEncoding’

Any help is highly appreciated,

Thanks,
Marcelo

I’ve been unable to duplicate the issue. See my heroku deployment here and code here.

Alternatively you can try adding the config option to a config file. Perhaps you can try that?

We also have a new version of the file uploader out. In the new version, as long as you do not provide an encoding arg, the warning should not show up. Try upgrading and let me know if you have issues still.