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 ...
0
votes
0
answers
207
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
1
answer
152
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 ...
4
votes
2
answers
601
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 "...
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
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-...
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
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 .
...
1
vote
1
answer
326
views
Failing to set cookie for SessionMiddleware due to 'invalid domain' (separate frontend/backend)
I set up Session Middleware with my FastAPI backend to authenticate my React frontend users, which worked with domain=127.0.0.1. Now that I've deployed both my frontend and my backend to two separate ...
0
votes
0
answers
125
views
Docker container, Cross-Origin Request Blocked, can't connect nginx website server to FastAPI
I'm trying to resolve Cross-Origin Request Blocked problem within my docker container.
This is my FastAPI code:
import os
from contextlib import asynccontextmanager
from fastapi import FastAPI
from ...
0
votes
0
answers
131
views
FastApi session cookies and AWS ECS
I have a FastAPI server that creates a user session with the following code:
@app.post("/session")
async def create_session(req: reqs.LoginRequest, response: Response):
session = uuid....
0
votes
0
answers
153
views
FastAPI Stops working afterawhile and then reboots after multiple failed requests
I have deployed my FastAPI onto azure in a container, problem is after awhile I'm getting this error
2024-04-18T09:48:52.022078363Z: [INFO] fail: Middleware[0]
2024-04-18T09:48:52.022122364Z: [INFO] ...
2
votes
0
answers
1k
views
FastAPI custom exceptions handler not working [duplicate]
I'm implementing custom exceptions in middleware and I want to raise an exception and expecting a JSON response with error message and code, when condition fails as mentioned below in middleware . But ...
2
votes
0
answers
1k
views
FastAPI CORS and Cookies ignored by browsers
I am using FastAPI to build a python back end, which I deploy to AWS/Azure/etc. but also develop locally on. For the life of me I cannot figure out my cookies and CORS locally nor deployed and hosted ...
0
votes
0
answers
257
views
How to get Azure bindings to FastAPI endpoint
How to pass a string starter from Azure http_trigger to the FastAPI endpoint?
Currently I'm hacking this by setting starter in context.trace_context.attributes
Or alternative to get the Azure bindings ...
0
votes
0
answers
318
views
fastapi: use middleware to generate a result in which the original result is included as an element [duplicate]
there is this code:
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
app = FastAPI()
@app.middleware("http")
async def response_middleware(request: Request, ...
0
votes
1
answer
722
views
receive_nowait raise WouldBlock error while uploading multiple files in FastAPI
I am trying to send multiple files from UI to fastAPI in formData. But the API is throwing error instantly when the API's is triggered.
async def createNewDirectory(files: Optional[List[UploadFile]...
0
votes
0
answers
260
views
Fastapi enabling Cors gives - error error serving tap http server: http: Server closed
Adding CORS to Python FastAPI Framework is giving this error
error error serving tap http server: http: Server closed
Configuration -
def get_app() -> FastAPI:
"""
Returns ...
1
vote
0
answers
144
views
FastAPI : Adding a custom middleware to specific endpoints / path operations [duplicate]
I am new to Python and FASTAPI. I would like to add custom middleware only to specific endpoints / path operations. Currently the middleware is getting executed for all the requests.
I tried to filter ...