File upload fails with Error: Request failed with status code 403

use

streamlit run main.py --server.enableXsrfProtection false

This should work if you are on working locally

1 Like

Thanks, Iā€™m hoping I have now got round this

1 Like

What do you mean by ā€œadding authenticationā€? The responders you list did not add any authentication, but rather disable XSRF - or did I miss something?

1 Like

This error bugged the hell out of me. It usually happened after a redeploy of my app on GCP or revisiting a stale page. The browser keeps the XSRF cookie and no longer matches the server. The fix that worked for me was a hard refresh in the browser.

Thanks! After struggling with this error for 3 days, this thing solved my issue.

This worked for me! Thanks

Hey all, hey @Charly_Wargnier,

Weā€™re having the same issue with streamlit==1.35.0. The file upload works locally, but not on the deployed app, and throws the AxiosError: Request failed with status code 403 error.

Here are a few additional info:

  • the app is deployed on a Kubernetes cluster managed by Azure
  • we have a service that maps the changing IP of the streamlit pod to a fixed IP
  • we have a proxy that associates a URL from our domain name to this fixed IP
  • the Streamlit container is root user on its pod
  • neither the container logs, or the pod logs, show anything particular when the error is thrown
  • there is an authentification required to access the app, but no authorization requirement

About the solutions previously mentioned:

  • we donā€™t want to downgrade to a previous version of streamlit
  • disabling XSRF and / or CORS protections does not look desirable as a long term solution.

What happens under the hood in st.file_uploader? Do we know where this particular exception is thrown from and under what circumstances? Any idea to solve this would be much appreciated :blush:

3 Likes

I have exactly the same problem ā†’ works locally but not on the deployed app. Have you been able to solve it?

No, not solved so far!

Itā€™s so strange, I have been working on my app on my work computer for a while with no issues. I am now working on my personal computer and am getting this 403 error. I just finished the whole app build to realize this bug is now poping up?!?!!

1 Like

Is there any update on this issue please? Still getting the error running Python 3.8.12 and Streamlit 1.35.0

Iā€™ve raised it as an issue to Streamlit:

1 Like

I put it enableXsrfProtection = false into config.toml but it does not work for. O was troubleshooting for daysā€¦
Finally i put ENTRYPOINT ["streamlit", "run", "./src/šŸ _Home.py", "--server.port=8080", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"] into my dockerfile and it works! streamlit version is 1.31.0

it works for me too, thanks a lot !

Thanks @Hugo_Angel,

I was trying to upload some images to s3, and after running with this flag it worked.

Actually, there are Python and Streamlit version compatibility issues. I also faced a similar problem, even when I tried to update my config.toml file too but I spent tons of time then got the idea that some versions of pythons do not fully support the dependencies of streamlit.

So far, I have installed the python version=3.12.4 and streamlit version=1.37.1, which allows all the dependencies to work smoothly, now all the file formats are uploading very smoothly without any problem.

Sadly even upgrading python to 3.12.4 doesnā€™t work for me.
Funny how things stopped working overnight without changing anything.

So far this works for me ā€¦ but only locally:

streamlit run main.py --server.enableXsrfProtection false

Using streamlit 1.38.0 , uploading xlsx files locally without running any flags, the upload works smoothly.
using the following command:

import streamlit as st
uploaded_file = st.sidebar.file_uploader(ā€˜Upload your file hereā€™, type=ā€˜xlsxā€™) # my file uploader sits on a sidebar

File upload failed.
ā€¢ There is a problem with your request. (403, 8d41fae42b951192-COK)

1 Like

Using python 3.11.2 and streamlit 1.37.1, still facing the error on my deployed appšŸ˜¢

It works locally with the
streamlit run app.py --server.enableXsrfProtection false,
but I hope not to disable the protection on my deployed app.

Does anyone have an update for this issue? Thanks!

1 Like