Excel file is treated as 'None type object


This code snippet is used to accept excel files. But when used it inside any function,The file is getting as ‘None type’ but when used globally,it is working properly

Code snippet:

data = st.sidebar.file_uploader(“Choose an Excel file”, type=[‘xlsx’])

Expected behavior:

I want the file to work properly

Actual behavior:

Inside the function,File is treated as none type object


Thanks for reporting this error. We are actively looking into this and will update you soon.

I am not seeing the reported error – can you share a complete snippet showing the issue?

This works fine for me with streamlit 1.25.0

import streamlit as st
import pandas as pd

def get_data() -> pd.DataFrame | None:
    data = st.sidebar.file_uploader("Choose an Excel file", type=["xlsx"])
    if data is not None:
        return pd.read_excel(data)
    return None

df = get_data()


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.