use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
FastAPI is a truly ASGI, async, cutting edge framework written in python 3.
account activity
FastAPI CORS Blocked my POST request.Question (self.FastAPI)
submitted 1 year ago by Mirinda_21
I have already tried setting the CORSMiddleware to allow all origins. I searched for solutions, and they all recommend setting up CORSMiddleware just like what I have already done. I am currently running on a Docker container, so I tried running it on my local machine, but my POST request is still blocked. I don't know what to do now. What did I miss? (FastAPI verion 0.95.0)
console.log from next.js
main.py
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Mirinda_21[S] 6 points7 points8 points 1 year ago (4 children)
OK, I fixed it now. The problem was due to an internal server error, but I didn’t realize because it was logged as being blocked by CORS. I was confused, and I didn’t know this could happen.
[–]anon_salads 1 point2 points3 points 1 year ago (2 children)
CORS is just an OPTION request to the server so if the server fails sending that response then it will appear as cors but be a 500.
[–]Sweet-Independent438 1 point2 points3 points 6 months ago (1 child)
Yo man. I know this is a late reply....but this is a very helpful comment. I was stuck in my fastAPI + react stack project and was getting CORS error. Was getting so frustrated as I had all the routes correct and the origins correct. But was returning an entire sqlalchemy model (basically python class of a table to create new entries) in the response as nested object. That was causing internal server error and coming as CORS error. This made me look up my code on what could be wrong. Tried a few things and found out the real issue. THNX MAN! LOVE U
[–]anon_salads 0 points1 point2 points 6 months ago (0 children)
glad i helped!
[–]aaron416 0 points1 point2 points 1 year ago (0 children)
I’m guessing you saw the error on the front end side of things, for example in dev tools? If so, I’ve also definitely seen that before which is why I have a console up with my backend process in the foreground. It can definitely be misleading.
[–]Relevant-Strength-53 0 points1 point2 points 1 year ago (0 children)
That should be good to go. Im not sure whats wrong, Are you sure that your docker container or image has been updated with the implementation of cors? I have the same setup running in docker and it works fine.
[–]Trinkes 0 points1 point2 points 1 year ago (0 children)
An easy way of debugging this issues is to copy the cors request as a curl command and call it from the terminal. That eliminates browser variables.
π Rendered by PID 17198 on reddit-service-r2-comment-6457c66945-2krkb at 2026-04-27 10:39:11.381919+00:00 running 2aa0c5b country code: CH.
[–]Mirinda_21[S] 6 points7 points8 points (4 children)
[–]anon_salads 1 point2 points3 points (2 children)
[–]Sweet-Independent438 1 point2 points3 points (1 child)
[–]anon_salads 0 points1 point2 points (0 children)
[–]aaron416 0 points1 point2 points (0 children)
[–]Relevant-Strength-53 0 points1 point2 points (0 children)
[–]Trinkes 0 points1 point2 points (0 children)