7,374 questions
Best practices
0
votes
1
replies
14
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
62
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 ...
1
vote
0
answers
45
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
109
views
A wrapper route to simulate a FastAPI request [duplicate]
My goal is to have a special route which receives name and payload for any other route and then (after doing some unpacking and decoding) call the target route which I prefer to go through HTTP ...
1
vote
1
answer
118
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 = ...
1
vote
2
answers
95
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
0
answers
34
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
1
answer
74
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
42
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
31
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
1
answer
56
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
1
answer
267
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 ...
3
votes
3
answers
88
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
157
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 `...
5
votes
0
answers
175
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 ...
0
votes
1
answer
78
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 ...
0
votes
1
answer
278
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:
...
2
votes
1
answer
61
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 ...
0
votes
0
answers
110
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
87
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'...
1
vote
0
answers
104
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,...
0
votes
0
answers
37
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 ...
1
vote
0
answers
208
views
Filter Parent class object based on list of child class values in Python | FastAPI | SQLAlchemy
Entities
class ParentEntity(Base):
__tablename__ = "parent_entity"
id = Column(Integer, primary_key=True)
status = Column(String)
config_id = Column(Integer, ForeignKey(&...
0
votes
1
answer
73
views
Cannot use Connection.transaction() in a manually started transaction
The code is used in many projects and works but in one service sometimes an error occurs:
"InterfaceError: (sqlalchemy.dialects.postgresql.asyncpg.InterfaceError) <class 'asyncpg.exceptions....
0
votes
1
answer
79
views
Why does adding Nmap port scanning inside a Celery task slow down my FastAPI + SQLAlchemy + PostgreSQL app?
I am building a scanning service using FastAPI + Celery + PostgreSQL + SQLAlchemy + Nmap.
I have a Celery task that performs WHOIS, DNS lookups, IP lookups, and then port scanning using python-nmap. ...