647 questions
1
vote
1
answer
132
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
99
views
Django unicorn asgi concurrency performan issue [duplicate]
Edit
Here is a similar question but is specifically about request sync block in async.
I'm just curious more about why the concurrency means they all take substantially longer - at different places in ...
0
votes
0
answers
39
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 ...
-1
votes
1
answer
72
views
How to manage Python 'websockets package' conflict for Kotak Neo API(V2) and Uvicorn(0.37.0)
I am building an application using Kotak Neo API (git+https://github.com/Kotak-Neo/Kotak-neo-api-v2.git#egg=neo_api_client) using Python Fast API.
Kotak Neo API uses websockets==8.1.
Python version - ...
2
votes
1
answer
65
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 ...
0
votes
0
answers
58
views
uvicorn always runs multiple thread irrespective of --workers switch
Tried to run my fastapi app in single thread and single process using uvicorn.
Have configured my Docker desktop to have only single-core-cpu.
root@e2bb2ef7dfcc:/app# nproc
1
root@e2bb2ef7dfcc:/app#
...
0
votes
0
answers
140
views
Uvicorn not getting trace id from otel in error logs (trace_id=0)
I have a test FastAPI application:
from fastapi import FastAPI, Request
from opentelemetry.exporter.otlp.proto.grpc import trace_exporter
from opentelemetry.instrumentation.asgi import ...
1
vote
1
answer
1k
views
Does FastAPI still need Gunicorn?
For a long time Gunicorn+Uvicorn was the default setup for running FastAPI in production. However, I recently came across a blog post saying:
In the meantime, this combination of Gunicorn and Uvicorn ...
0
votes
0
answers
56
views
How to set cookie for data block in config.yaml of continue?
I'm trying to capture chatInteraction and chatFeedback from continue with below config details in config.yaml of continue plugin.
But I see no response and no logs being printed during debug in ...
1
vote
2
answers
84
views
Running Uvicorn on Mac command line results in error uvicorn: error: unrecognized arguments [closed]
When I run my FastAPI app with the Uvicorn command, the command line args are not recognized:
(env) mydir$ uvicorn main:app --port 8000 --host 0.0.0.0 --reload
...
uvicorn: error: unrecognized ...
0
votes
2
answers
96
views
FastAPI and uvicorn not updating
I've got 2 separate issues with FastAPI. I'm going through a course and on the tagging part, my tags aren't showing in the docs. Additionally, for 1 endpoint that I provided status codes (default to ...
0
votes
1
answer
113
views
Uvicorn reload_excludes not working for one directory but working for another identical directory
I'm running a FastAPI application with uvicorn and using reload_excludes to prevent the server from reloading when files are added to certain directories. The issue is that the exclusion works for one ...
2
votes
0
answers
301
views
Uvicorn workers greater than one apparently reduce performance by half
Update 2: The following results do not hold when installing Uvicorn using pip install uvicorn[standard] which installs Uvicorn with Cython-based dependencies (where possible) and other optional extras....
2
votes
1
answer
608
views
LangGraph resume after interrupt is not working properly when running with more than 1 worker in uvicorn
I am new to langGraph and I have simple agentic app built using langGraph and FastAPI.
Whenever the FastAPI application is running in docker with more than 1 workers, CMD:
["uvicorn", "...
2
votes
0
answers
84
views
Python uvicorn app opens a cmd - how to stop it?
I've been building a WebSocket application and I opted for Python FastAPI + Uvicorn for server side. Having pretty much finished the app, I decided to pack the server into an .exe file. Even though I ...
0
votes
0
answers
125
views
Run FastAPI in a Windows Service
i have a big problem. I try to run FastAPI as a Windows Service after i converted the scripts in .exe with pyinstaller.
This is my Code in apy.py:
from fastapi import FastAPI, UploadFile, File, ...
0
votes
1
answer
541
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
...
0
votes
0
answers
33
views
Django with PyODBC and Oracle 8i: Temporary Table Issues After a Day
I'm using Django with PyODBC to connect to an Oracle 8i database. I run my Django application using Uvicorn as an ASGI server. However, after running for a day, I encounter an issue where temporary ...
0
votes
0
answers
135
views
FastAPI Dev taking very long to start the server whereas uvicorn main:app --reload --port 8000 works
I have a very simple FastAPI server.
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello, World!"}
@app.get("/...
2
votes
1
answer
107
views
Is there any way to serve a Django application using preload, ASGI, and SO_REUSEPORT?
I can't find a way to serve our large Django application using all three of preload, ASGI, and SO_REUSEPORT.
Without preload and fork we use much more memory (gigabytes).
Without ASGI we can't serve ...
1
vote
1
answer
481
views
FastAPI Global Timeout Middleware Not Working for Sync Routes [duplicate]
I am trying to enforce a global request timeout in my FastAPI application using a custom TimeoutMiddleware. The middleware is supposed to cancel any request that takes longer than the specified ...
0
votes
0
answers
161
views
FastAPI application redirect to HTTP and not HTTPS
Im using FastAPI via Uvicorn, and deploying my application to an Azure App Service. Its being deployed to
# Start
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", ...
4
votes
0
answers
494
views
Gunicorn / Uvicorn extremely rare 502 Errors
We observed an issue with our containerized Python FastAPI application, which we deploy using Gunicorn and Uvicorn on Kubernetes. In extremely rare cases (~1 in 100.000) a single request seem to be ...
4
votes
1
answer
240
views
FastAPI lifespan does not work when running with docker
My app with lifespan defined like this:
@contextlib.asynccontextmanager
async def lifespan(app:fa.FastAPI):
print("LIFE SPAN: Start up")
yield
print("LIFE SPAN: Shutdown&...
3
votes
0
answers
157
views
Limit FastAPI/gunicorn/... worker to certain endpoints to save memory
I have a FastAPI application with multiple endpoints, and each endpoint uses certain memory intensive objects (ML models). This works fine when I only have one worker, but I am worried about memory ...
0
votes
1
answer
364
views
TCP connections in CLOSE_WAIT state not closing in the Microservice(FastAPI with Socket.IO) running as Uvicorn(ASGI Web Server)
Context
Microservice based out of FastAPI microframework with SocketIO server wrapped as ASGI application executed on Uvicorn Webserver.
The service has several socket events written to handle events ...
0
votes
1
answer
1k
views
My FastAPI service is giving CORS errors from my website running on localhost when I run the API in VSCode, but not if I run it on the command line
I have an API built in FastAPI hosted with uvicorn. I also have a website build in next.js. My typical workflow is to run the API locally on the command line and it will be hosted on localhost:8000, ...
0
votes
1
answer
199
views
Can't find static or templates directory when running in FastAPI in Docker container
So I've migrated from Quart to FastAPI for a Python application and can run it fine one desktop or VM, but am unable to run in a Docker container. My Dockerfile is this:
FROM python:3.13-alpine
...
1
vote
1
answer
910
views
Port in code not being included when starting my Python Uvicorn app?
I have my code starting as such:
if __name__ == "__main__":
uvicorn.run(
app,
host="0.0.0.0",
port=3001, # Desired port.
)
I'm starting my ...
6
votes
2
answers
2k
views
Why does my FastAPI application redirect to HTTP and not HTTPS?
I'm using FastAPI, running via Uvicorn, with the below (default) config:
app = FastAPI(..., redirect_slashes=True)
This should reroute e.g. https://example.com/test/ to https://example.com/test.
When ...
2
votes
0
answers
197
views
How can I run Uvicorn in ECS?
I have a FastAPI/Uvicorn/SQLAlchemy app that I'm trying to run in ECS. I have successfully run the app via docker compose, but when I try to deploy the container in ecs I get the following error:
...
1
vote
1
answer
2k
views
FastAPI child process gets killed even with enough unused RAM and CPU left in the machine
I have a FastAPI server which fetches a lot of data from a database and does some data crunching ( ~20GB ) of data.
@app.post('/eval')
def exec_code(event: CodeModel, response: Response):
try:
...
1
vote
0
answers
182
views
Twilio POST request showing GET error: 405 Method Not Allowed
The issue is when Twilio sends a POST request to the /incoming-call endpoint, my server is returning a 405 Method Not Allowed error. The error log also shows that the server is attempting to handle ...
3
votes
1
answer
1k
views
FastAPI RuntimeError: Expected ASGI message 'websocket.accept', 'websocket.close', or 'websocket.http.response.start' but got 'http.response.start'
I have server like:
main.py
import socketio
from fastapi import FastAPI
app = FastAPI()
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*")
sio_app = socketio....
1
vote
0
answers
172
views
Python: FastAPI not accepting SQLModel as a return type on routes
I'm making an API based on the FastAPI docs (https://fastapi.tiangolo.com/tutorial/sql-databases/#install-sqlmodel). I have noticed this docs are kind of deprecated due to @app.on_event("startup&...
1
vote
1
answer
103
views
Local development server with uvicorn
It's possible to add ASGI support to python manage.py runserver, so the local development server, by installing daphne and adding it to INSTALLED_APPS.
See docs here. This is how the result looks:
...
0
votes
1
answer
343
views
invalid command name 'main:app' when I execute "uvicorn main:app --reload" [duplicate]
When I try to execute the command uvicorn main:app --reloadfor start my local server, the VSCode terminal throws the error invalid command name 'main:app'. The code below imports a variable from the ...
1
vote
1
answer
89
views
GCP Cloud Run Container Behavior - ModuleNotFoundError
When Cloud Run runs a container image, the container fails differently than when I run it locally.
I added this try/except in app/main.py to debug the divergent behaviors:
print(f'cwd is {os.getcwd()}'...
1
vote
0
answers
233
views
How do you make gunicorn forward SIGINT to uvicorn when running inside Docker?
I have a script running inside Docker (using wsl2), started with CMD, that is behaving strangely w.r.t. SIGINT signals. This is the script:
#!/usr/bin/env bash
python manage.py init_db
exec gunicorn ...
0
votes
0
answers
488
views
WebSocket Disconnects After 60-70 Seconds in FastAPI (Uvicorn) – Works in Postman, Fails in Browser and Mobile Clients
I’m implementing a WebSocket connection using FastAPI with Uvicorn as the server. The WebSocket works fine when tested through Postman, but disconnects after 60-70 seconds when accessed through web ...
0
votes
0
answers
163
views
Large file transfers slow with HTTP but fast with SCP
I need to transfer 432 MB images between 2 Linux computers which are on the same fast network. scp transfers each image in less than 1 second. The code below using HTTP takes between 3 and 8 seconds ...
0
votes
0
answers
160
views
How do I connect uvicorn/fastapi through docker container?
I'm currently building an app that connects to an API server through a script. Here’s how I create posts by connecting to the API server:
api_url = "http://localhost:8013/posts/"
...
0
votes
1
answer
347
views
TypeError: __call__() missing 1 required positional argument: 'context' error when deploying on GCP
I want to deploy a FastAPI app in Google Cloud Platform (GCP), specifically with Vertex AI.
These are my files:
main.py
import os
import uvicorn
from dotenv import load_dotenv
from fastapi import ...
0
votes
1
answer
270
views
Python FastAPI no console mode with Uvicorn
I am building an app. While deploying in Windows server I don't want the console opening. But when I try to do so in .pyw form it does noting
run.pyw 1>stdout.txt 2>stderr.txt calls the ...
0
votes
1
answer
617
views
Running SQLAlchemy with uvicorn: Elegant way to ensure that multiple workers do not try to call Metadata.create_all?
I am working on one a Python application which uses a FastAPI, SQLAlchemy, Pydantic/psycopg2, and Uvicorn stack. The project is structured in a way similar to the "Bigger Applications - Multiple ...
0
votes
1
answer
611
views
Unable to run Uvicorn server/FastAPI app through Docker [duplicate]
I am new to computer networks and Docker, and I'm trying to deploy and run a small FastAPI app using Docker. The app works successfully when I run it locally with Uvicorn, but it fails to run when I ...
0
votes
0
answers
179
views
logging to file with uvicorn web-server
I'm trying to write some log messages to a file called log.txt, but I'm facing an issue while trying to do this with the Uvicorn server.
If I call the logger before creating and configuring the ...
0
votes
0
answers
65
views
Update deep learning models to memory every day with Uvicorn FastAPI without reloading
I have a FastAPI backend that needs to load new deep learning models everyday to memory. Models loads for the first time when FastAPI starts or force reload.
I have a class Predict and an endpoint to ...
0
votes
1
answer
2k
views
Facing issue while loading FastAPI swagger URL
I am trying to run FastAPI application using uvicorn and I am using Python for this. After running the command "uvicorn app.main:app --host 0.0.0.0 --port 8000 --log-level debug", I am able ...
1
vote
1
answer
424
views
How to log a request in FastAPI when an exception occurs which is handled inside submodule?
Imagine I have a FastAPI backend application exposing the following test endpoint:
@router.post("/my_test")
async def post_my_test(request: Request):
a = do_stuff(request.var1)
b = ...