lungsang
lungsang

Reputation: 167

AttributeError: 'NoneType' object has no attribute 'name' with streamlit

I am trying to display a pipeline script on the UI with streamlit and facing this error AttributeError: 'NoneType' object has no attribute 'name'

My code is as follow

data_file = st.file_uploader("Upload raw file", type=["docx"])

    with open(os.path.join("/home/lungsang/Desktop/levelpack-UI/content/A0/1 docx-raw", data_file.name),
              "wb") as f:
        f.write(data_file.getbuffer())

The error i am getting: error on the UI

If you guys know how to avoid this small error showing on the UI, please do share here, it would help alot:)

Upvotes: 0

Views: 1442

Answers (1)

Jamiu S.
Jamiu S.

Reputation: 5721

Put data_file to a condition of if statement

data_file = st.file_uploader("Upload raw file", type=["docx"])

if data_file is not None: # Added missing if statement
    with open(os.path.join("/home/lungsang/Desktop/levelpack-UI/content/A0/1 docx-raw", data_file.name),
              "wb") as f:
        f.write(data_file.getbuffer())

Upvotes: 1

Related Questions