streamlit: st.file_uploader AxiosError 413 when app is deployed

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

I have encountered an error that only shows when the application is deployed outside of the localhost. Specifically, when using st.file_uploader for files above 10mb (where the limit for the file is set higher than this). You are able to upload a file of say 16mb however to the end of the upload you see the error below (the full error reads - ‘AxiosError: Request failed with status code 413’) : image Keeping the app the same but then playing with the file size I was able to determine that the threshold for the error is 10mb because if I upload a file slightly smaller than this the app works: image

Reproducible Code Example

import streamlit as st

container = st.container(border=True)
with container:
 uploaded_file = st.file_uploader("Choose a CSV file to see your analytics. Don't worry this data isn't 
 stored outside the session", type='csv')

st.dataframe(uploaded_file)

Steps To Reproduce

  1. Use the code provided
  2. Ensure that the app is NOT running on localhost (i.e., needs to be deployed)
  3. Upload a file that is above 10mb
  4. Error should occur

Expected Behavior

Please see summary - but if a file is uploaded that is below 10mb the file should upload as expected and display below the uploader. If the file is above 10mb then you should see the Axios error.

Current Behavior

I have provided the error above: ‘AxiosError: Request failed with status code 413’

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.35.0
  • Python version: 3.8.12
  • Operating System: Windows 11
  • Browser: Google Chrome

Additional Information

Issue has been present for a while according to community cloud:

https://discuss.streamlit.io/t/file-upload-fails-with-error-request-failed-with-status-code-403/27143/69

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 36
  • Comments: 15 (1 by maintainers)

Most upvoted comments

I’m facing the same issue. --server.enableXsrfProtection false solves the issue locally - but it doesn’t seem like a good idea to do this in production due to the security risks. image

  • Error: AxiosError: Request failed with status code 403
  • Python Version: 3.11
  • Streamlit Version: 1.37.1

Using --server.enableXsrfProtection false actually solved the problem locally, still I’m concerned what caused it in the first place.

In case it helps with the resolution, or further debugging: I got the same error just as I upgraded to version 1.37.0 from version 1.21.0. I believe I am in the same position as @erwan2397 since in my case it happens locally with a file that is 21kb.

After some initial research, I found many forum topics related to this issue (example 1, example 2, example 3, example 4) but with no clear fix to me. I could not find any relationship to the cookies, but creating the toml file suggested in some discussions did not help either.

I am actually not sure if the AxiosError you got was 413, or was it 403? (before the title change). Mine is 403, although it might not be the same issue… Otherwise, @dneadle I feel that you might need to reopen the issue since the solution that was provided was regarding the file size, and in our case that was not the problem. Has that fixed it for you? To me, the file_uploader is currently not working properly (while before the upgrade it was).

The issue I found has a workaround by using the parameters --server.port=8000 --server.address 0.0.0.0 --server.enableXsrfProtection false when launching, as found by user al-yakubovich a few days ago and posted on this discussion.

I am happy to open a new issue if needed. Thank you 😃

hi @kajarenc,

Based on the further comments here suggesting that this isn’t an isolated instance and is still present for other users. It is not a consistent issue but one that is still present. Please can the issue be reopened and looked into further?

I know it is hard when the issue can’t be replicated however another of our projects with 1.35.0 is also impacted by this now for a handful of users (not all and not all the time).

Thanks

For the record, this bug description is misleading:

  • the bug is not specific to deployment, it can happen when running locally
  • the bug is not related to file size, it can happen with very small size (I had the error with 67kb file)
  • it is likely still the same error as described in this discussion (apparently related to some cookie?)

To me it seems to happen randomly, making it very hard to provide reproducible code.

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits