7,374 questions
0
votes
0
answers
21
views
API response is in stream. How should I convert that in dart so I can show it in the UI?
The thing is this
Response: agent-stream-start:Hello, Faseeh ur Rehman! How can I assist you today?
This is how the response is returned from the call. I am working on a flutter mobile application ...
1
vote
1
answer
60
views
Strange behaviour: FastAPI and Curl not working with "localhost" but ok with 127.0.0.1
When I run my first sample (first official tutorial) using FastAPI and I notice something weird with the test using curl.
Launch the server with:
fastapi dev main.py
and to test the endpoint, I ...
0
votes
1
answer
41
views
Why does my websocket connection get blocked?
I have a simple FastAPI server with just one WebSocket endpoint. It receives a terminal command, executes it locally, and broadcasts the stdout to the client every second:
from fastapi import FastAPI, ...
1
vote
1
answer
38
views
FastAPI-Login optional dependency always returns None even with a valid token
I'm building a login system with FastAPI and fastapi-login. I already have a /register route working.
My goal is:
If a valid token is present, allow access to certain routes.
If no token or an invalid ...
0
votes
1
answer
25
views
FastAPI: Not able to use AsyncMock to fetch mock rows from aiosqlite (async sqlite3 library) while testing the endpoint
I am using Python 3.13.2
I am trying a sample use case of using AsyncMock to simulate fetching of mock rows from DB to test my endpoint (using pytest-asyncio).
I have also included a non-mock endpoint ...
0
votes
1
answer
36
views
FastAPI: /v1/modules returns {"detail": "Not Found"} even though router is defined
I have a FastAPI app that I start with:
uvicorn app.main:app --reload
In the code I have (simplified):
# routers.py
API_PREFIX = "/v1"
def register_routers(app: FastAPI) -> None:
...
0
votes
0
answers
68
views
DuckDB connection.execute from fast api code changes &( to amp;( in a read_xlsx query [closed]
I am using a fast api code and just reading an excel file.
The file is read as
query = f"""
Describe SELECT *
FROM read_xlsx({file_path}, sheet='SpecialChar test&()@#$%^&()+{}')...
-1
votes
0
answers
28
views
FastAPI text-classification API returns 42 while deploying [closed]
I had a chance to deploy a simple text-classification model using FastAPI and exposing a /predict endpoint that should accept a text input. But, every time I send a POST request with a string body the ...
0
votes
0
answers
52
views
Speed up LangGraph REACT + RAG.(Multi-Agent Chatbot)
I’m trying to reduce latency in a LangGraph-powered chatbot that uses 14 REACT-style agents. The RAG layer pulls external knowledge from a vector DB.
The issue:
The REACT reasoning loop triggers ...
Best practices
0
votes
1
replies
26
views
Similar approach for allowed_host ip whitelist filtering in django, but in fastapi
I want to know the best practice for IP whitelist filtering in FastAPI. I'm used to writing Django APIs, but now I need to get the work done using FastAPI. Anyways, the ALLOWED_HOSTS feature in django ...
1
vote
0
answers
89
views
Issue with sqlAdmin under https domain and path
Let me start from middle. I have been play around for a long time with these three part:
nginx which handles the path
Fastapi server
sqlAdmin
The url https://example.com/gem/admin must be passed to ...
-3
votes
0
answers
41
views
Previous Twilio/ElevenLabs calls are being re-initiated when starting a new batch. Is this a state accumulation issue?
I am building an automated bulk calling system using Python (Async), MongoDB, and the ElevenLabs Conversational AI integration with Twilio (client.conversational_ai.twilio.outbound_call).
I am running ...
1
vote
0
answers
73
views
How to delete a persistent chromadb collection
I want to delete a persistent chromadb collection after 12 hours, I am currently saving the time the collection was created in mongodb and then check it against current time, if it it is 12 hours old ...
0
votes
0
answers
34
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 ...
Best practices
0
votes
5
replies
212
views
What is the ideal production-grade infrastructure to deploy a Python FastAPI service for computing option Greeks (e.g., Black–Scholes)?
I am building a python service to compute Greek values using python, but I have never worked on python, and I would appreciate advice from the experienced python devs as it would help me a lot.
FLOW
...
1
vote
1
answer
148
views
Uvicorn /FastAPI strange behavior
I create simple app using (python 3.11, uvicorn 0.38.0, fastapi 0.120.2):
import os
import time
import asyncio
import uvicorn
from fastapi import FastAPI
from fastapi import BackgroundTasks
app = ...
2
votes
0
answers
115
views
Why does my microservice return inconsistent results when using Redis caching with async SQLAlchemy?
I’m working on a Python FastAPI microservice that uses async SQLAlchemy (2.0) for database access and aioredis for caching query results.
The goal is to reduce load on a PostgreSQL cluster by caching ...
1
vote
2
answers
146
views
Why does my FastAPI websocket connection close immediately after authentication?
I’m building a secure messaging app using FastAPI with JWT authentication and websockets.
My issue is that after the client connects with a valid token, the websocket closes right away with code 1006.
...
0
votes
1
answer
104
views
Combining Pydantic Models and File Uploads
I'm trying to type hint my fastAPI to take both a BaseModel pydantic class for various arguments and some seperate files. I also want to add a description for all of the inputs on http://127.0.0.1:...
0
votes
0
answers
41
views
“Operation not permitted” when creating directories and saving files in Azure App Service (FastAPI on Linux)
I’m hosting a FastAPI application on Azure App Service (Linux, Python 3.12).
The deployment works, but the logs repeatedly show the following errors:
chown: changing ownership of '/temp': Operation ...
2
votes
0
answers
94
views
Using Prefect with FastAPI is still displaying old logs
I tried using Prefect with FastAPI project. Then when I updated logs and redeployed the repo as well as Prefect deployments and flows. It runs and displays the logs (Basically , Prefect is still ...
2
votes
1
answer
75
views
`BackgroundTasks` only execute when declared inside an async dependency
I’m running into strange behavior in FastAPI where my BackgroundTasks only execute when declared inside an async dependency. No exception is raised, the route returns normally, but the background job ...
0
votes
0
answers
70
views
How to mock multipart/form-data with pytest?
I have a POST endpoint with fastapi that goes a little like this. This takes in an excel file and turns it into a pandas dataframe.
@router.post(
"/endpoint/upload_excel",
status_code=status....
0
votes
0
answers
43
views
FastAPI: PDF upload works when called directly inside Kubernetes or locally, but results in blank files when routed through API Gateway/NGINX
I’m running a FastAPI service in Kubernetes that accepts multipart/form-data uploads and stores files in S3.
The upload endpoint works fine when I call it directly inside the cluster using the service ...
0
votes
0
answers
93
views
Azure Functions (FastAPI - AsgiFunctionApp): Logs appear in Application Insights but not in Invocations tab — Category issue?
Problem Summary
I'm using AsgiFunctionApp to wrap FastAPI in Azure Functions, but my application logs are not appearing in the Azure Portal's Invocations tab. The logs do appear in Application ...
0
votes
0
answers
34
views
Perform Google login in react native app with own API
I am developing a mobile application using React Native. In this phase I am trying to connect it to my APIs (made using FastAPI with Authlib) to perform authentication with Google.
I do not know if I ...
0
votes
0
answers
33
views
Soul Machines Orchestration servers Query format
I'm working on integrating my custom RAG into Soul Machines avatar to make the conversations of avatar according to my RAG Database. I'm connecting RAG with soul machines using orchestration server(...
0
votes
1
answer
68
views
Pytest 404 status codes on some FastAPI tests
I have a FastAPI router that I am trying to run some unit tests on using pytest. 7 of the 8 tests pass, but 1 keeps returning a 404, and failing the assertion to check the status_code == 200 (it is ...
1
vote
0
answers
79
views
Error 401 when authenticating with Bearer to fastapi_users
I don't understand what the problem is. Everything seems to be working fine. I've included all the code below.
My code structure is like this:
service.py
import uuid
from typing import Optional
from ...
2
votes
1
answer
407
views
DeprecationWarning 'HTTP_422_UNPROCESSABLE_ENTITY' is deprecated. Use 'HTTP_422_UNPROCESSABLE_CONTENT' instead
I'm working on AWS EC2. I created a virtual environment and installed all the necessary dependencies. I connected to it via VSCode, and when I try to start the server using the airflow standalone ...
0
votes
0
answers
31
views
Why doesn't SqlModel preform insert query in Llamaindex tool
I have an ai agent made with Python Llamaindex, FastAPI and SqlModel. I want to log the ToolCall in "search_documents" function but it never works.
The only problem is that ToolCall is not ...
3
votes
3
answers
100
views
How to handle custom date format (dd/mm/yyyy) in query params with inherited model?
I'm building a FastAPI app (actually a small package) that defines a base model for a webhook endpoint. Other developers can inherit from this model and extend it for their own use cases.
The webhook ...
2
votes
1
answer
69
views
How to ensure webhook requests are routed to the same FastAPI worker that initiated the request
I’m working on a FastAPI service deployed with Uvicorn using multiple workers to handle voice communication with Twilio, and I’m running into a routing problem.
Current architecture:
A client sends a ...
2
votes
1
answer
172
views
How to add aiokafka producer to FastAPI properly?
I am creating FastAPI and aiokafka endpoint. How to add aiokafka producer properly?
from aiokafka import AIOKafkaProducer. The function is woking, but too long. Found out that the problem deals with `...
-1
votes
1
answer
55
views
Azure deployment works for frontend but backend keeps failing (F1 free tier) [closed]
I'm trying to deploy a FastAPI backend to Azure and hitting constant issues, but my React frontend deployed fine to Azure Static Web Apps using the SWA CLI.
Frontend (Working):
Deployed successfully ...
5
votes
0
answers
231
views
Downgrading OpenAPI 3.1 generated by FastAPI to 3.0 for Azure API Management
I’m building a FastAPI application in Python. When I navigate to the /openapi.json endpoint, FastAPI generates an OpenAPI 3.1 specification.
However, Azure API Management (APIM) only supports OpenAPI ...
1
vote
1
answer
101
views
Order of execution in FastAPI async generators
This is the code
@router.post("/tel/verify-otp",
summary="Verify OTP and update user tel number"
)
async def verify_tel_otp(
command: ...
0
votes
1
answer
84
views
Kubernetes pod restarts caused by health check timeouts in Python FastAPI service during heavy document processing
I have a Python FastAPI service that primarily serves one main endpoint, along with an additional endpoint for health checks.
The main endpoint processes documents ranging from small to very large and ...
-4
votes
1
answer
85
views
Adding Custom Validation to Pydantic Models (TypeError: Object of Type ValueError is not JSON Serializable)
I am trying to set up custom validation for pydantic models. According to the the pydantic docs, custom validators can be applied to a field using the Annotated Pattern or field_validator() decorator ...
0
votes
1
answer
428
views
How to connect FastAPI with PostgreSQL using SQLAlchemy and async sessions?
I’m building a small project using FastAPI + PostgreSQL and I want to use async SQLAlchemy sessions for queries.
I’ve seen examples with SessionLocal, but I’m confused about how to properly set up:
...
0
votes
0
answers
58
views
How to update user status in MySQL after app purchase confirmation via Google Play?
I have an app built with Flet (Python) hosted on Railway alongside MySQL, and built with a Flutter webView for Google Play.
I want to update the "account_type" column in the MySQL database, ...
2
votes
1
answer
62
views
FastAPI won't recognize module changes
I keep my SQL hooks in a separate module. I added a function, and for the life of me I cannot get it to be registered in the fastAPI. I can alter the main file of the fast API, but it just keeps ...
-1
votes
0
answers
61
views
After load testing, should memory return to baseline or stabilize higher? How to distinguish normal from a leak? [duplicate]
I’m trying to understand the expected memory behavior of a Python service (FastAPI in my case, but the question is more general).
Scenario:
Baseline memory: service starts around ~600 MB.
During load: ...
0
votes
0
answers
114
views
How to define self-referencing relations in Python SQLModel ORM
I'm developing a FastAPI application, a file manager system, and I'm using PostgreSQL as the database. To define database entity models in my code, I previously used SQLAlchemy, but now I switched to ...
0
votes
0
answers
28
views
FastAPI streaming response getting buffered instead of word by word using fetchEventSource in NextJS 14
I am using fastAPI streaming-response to get the ChatOllama stream. It work well with curl.
But fetching event source from nextjs, feels like rest API, even tho event stream is showing in the network ...
0
votes
0
answers
99
views
Apisix route for swagger end point not working
I have APISix routes for my fastapi backend. Service endpoints work well. But swagger docs are not rendered.
While http://127.0.0.1:8000/docs render docs, but apisix route configured for /docs/* doesn'...
4
votes
3
answers
260
views
Pytest in FastAPI + Postgres results in: <sys>:0: RuntimeWarning: coroutine 'Connection._cancel' was never awaited
I'm writing tests for my fastapi application that uses asynchronous posgtres connection:
# backend/database/session.py
from sqlmodel import SQLModel
from sqlmodel.ext.asyncio.session import ...
1
vote
0
answers
111
views
Having trouble with asyc_sessiomaker in FastAPI
I'm buiding endpoints with FastAPI, PostgreSQL as database, and the driver is asyncpg associated with SQLAlchemy for asynchronous. As mentioned in the title, I'm having trouble with async_sessionmaker,...
4
votes
1
answer
230
views
How to add objects/links to a set of links in beanie?
Assume that I have these Beanie Documents which are based, by the way, on Pydantic Models:
File name: models.py
from beanie import Document, Link
class A(Document):
first: int
second: str
...
0
votes
0
answers
41
views
Should I cache FastAPI FileResponse outside the endpoint?
In the following code, I made an optimization: instead of reading the index.html file on every request, I stored the FileResponse in a global variable and return it in the endpoint function. The site ...