streamlit.errors.StreamlitAPIException: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).
Traceback:
File "/home/adminuser/venv/lib/python3.12/site-packages/streamlit/runtime/fragment.py", line 248, in wrapped_fragment
result = non_optional_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mount/src/st_test/streamlit.py", line 694, in poechat
st.download_button(label='Download',data='deneme', file_name='deneme.txt', mime='text/txt')
File "/home/adminuser/venv/lib/python3.12/site-packages/streamlit/runtime/metrics_util.py", line 410, in wrapped_func
result = non_optional_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.12/site-packages/streamlit/elements/widgets/button.py", line 362, in download_button
return self._download_button(
^^^^^^^^^^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.12/site-packages/streamlit/elements/widgets/button.py", line 621, in _download_button
raise StreamlitAPIException(
Hatayı nasıl çözebilirim
Assistant
Streamlit’s st.download_button is a useful feature for allowing users to download data directly from your app. The error you're encountering likely stems from an issue with the parameters you're passing to st.download_button. Let's break down potential causes and how to resolve them.
1. Incorrect MIME Type
Issue:
You specified mime='text/txt'. The MIME type 'text/txt' is not a standard MIME type, which can cause Streamlit to raise an exception.
Solution:
Use a standard MIME type for plain text files. Change 'text/txt' to 'text/plain'.
Issue:
While passing a string ('deneme') is generally acceptable for text files, ensure that the data you're passing aligns with the expected MIME type and file extension.
Solution:
If you're downloading more complex data (like binary files), ensure it's in the correct byte format. For text files, strings are fine.
Example for Text Data:
python
text_content = "This is a sample text file."
st.download_button(
label='Download Text',
data=text_content,
file_name='sample.txt',
mime='text/plain'
)
Issue:
Ensure that you're using a compatible version of Streamlit that supports st.download_button. Older versions might not have this feature or might have bugs related to it.
Solution:
Update Streamlit to the latest version.
Update Command:
bash
pip install --upgrade streamlit
4. Check Streamlit Logs for Detailed Error
Since the original error message is redacted, checking the logs can provide more insight.
If You're Using Streamlit Cloud:
Click on 'Manage app' in the lower right of your app.
Navigate to the 'Logs' section to view detailed error messages.
If You're Running Locally:
Check the terminal or console where Streamlit is running to see detailed traceback and error messages.
5. Example of a Working st.download_button Implementation
Here's a complete example to ensure everything is set up correctly:
python
import streamlit as st
def download_example():
# Sample text data
text_data = "Hello, this is a sample text file."
st.download_button(
label="Download Text File",
data=text_data,
file_name="sample.txt",
mime="text/plain"
)
if __name__ == "__main__":
st.title("Download Button Example")
download_example()
Summary
The primary issue in your code is likely the incorrect MIME type 'text/txt'. Changing it to 'text/plain' should resolve the StreamlitAPIException. Additionally, ensure that your data format matches the MIME type and that you're using a compatible version of Streamlit. If problems persist, consult the Streamlit logs for more detailed error information.
If after these changes you continue to experience issues, please provide more details or the specific log messages, and I’d be happy to assist further!