38 questions
0 votes
0 answers
23 views
Keycloak Middleware Issue: Empty preferred_username in get_user Object
Keycloak Middleware Issue: Empty preferred_username in get_user Object I'm using fastapi_keycloak_middleware to secure my FastAPI app with Keycloak. I'm having trouble mapping the preferred_username ...
2 votes
1 answer
97 views
FastAPI CORS error despite correctly configured CORSMiddleware
The code works locally but when I put it on an EC2 machine and change the CORS origins accordingly it fails. I've checked the URL for 2 hours straight. I copied and pasted it from the page that loaded ...
0 votes
0 answers
210 views
Starlette/FastAPI Default Exception Handler Overriding Error [duplicate]
I'm trying to override the default exception handler in a FastAPI application so I can log any exceptions that happen. The problem that I run into is that my handler seems to run as it logs what I ...
0 votes
0 answers
108 views
User ID from Azure Web App authentication
I am working on a webapp which has these: FastAPI - Backend Chainlit - Frontend The chainlit frontend is mounted on the FastAPI backend. He is how it looks in the code: @app.get("/") async ...
0 votes
1 answer
153 views
How to handle dynamic origin in FastAPI
I'm implementing a FastAPI backend where I want to allow CORS requests only from a predefined list of default origins and dynamically loaded origins stored in the database. However, when the frontend ...
0 votes
1 answer
143 views
How to check the response type in the middleware?
I'm trying to create a middleware, the logic of which depends on the response type. Specifically, I need to close the db session after the response has been sent for "immediate" response ...
4 votes
2 answers
603 views
Keep context vars values between FastAPI/starlette middlewares depending on the middleware order
I am developing a FastAPI app, and my goal is to record some information in a Request scope and then reuse this information later in log records. My idea was to use context vars to store the "...
1 vote
1 answer
367 views
How to add a shutdown event in FastAPI using lifespan in middleware?
FastAPI profiler code if server_app is not None: server_app.add_event_handler("shutdown", self.get_profiler_result) I think Starlette is not allowing both lifespan and ...
0 votes
1 answer
535 views
FastAPI WebSocket returns 403 Forbidden when trying to access via Postman
I am trying to run a websocket from a server where it watches a file and broadcasts any changes to the file over the websocket. This is my code: import os import json import uvicorn import asyncio ...
1 vote
1 answer
302 views
How do I make FastAPI URLs include the proxied URL?
I have a FastAPI application that is behind a NextJS reverse proxy. I'm using NextJS rewrites, which sets the x-forwarded-for header to the externally-visible hostname and port. The rewrite looks ...
1 vote
1 answer
72 views
Interceptors.request unable to add a request header
I have a react nextJS project, and the following code: import axios from "axios"; import config from '@/app/settings/config'; import { configConsumerProps } from "antd/es/config-...
1 vote
1 answer
227 views
Middleware for fetching the user from database for each request
I have a (SQLAlchemy) User model as follows: class User(BaseModel): id: uuid: Mapped[UUID] = mapped_column(UUID, ...) I need to check if the user exists in DB for every request. I know I should ...
0 votes
0 answers
54 views
CORS issue with FastAPI despite using a specific middleware [duplicate]
I have a CORS issue with this code from localhost:3000. I have checked the fastAPI documentation and add some code to tackle the issue. But there is no change and I have always the error. Here is my ...
0 votes
0 answers
97 views
Fast API POST Request to retrieve data from Google Cloud MySQL giving Recurring 404 Error [duplicate]
I am creating a web app that makes use of the amazon product advertising API. I haven't started on this part of the functionality as I am still creating the base web app. I have already created a ...
0 votes
1 answer
154 views
FastAPI object from middleware to actual endpoint [duplicate]
I try to build a middleware for my app. I need a way to create some object in my middleware function and i want to have access to that object in a next endpoint method . Please see my code example . ...