Questions tagged [asgi]

ASGI stand for Asynchronous Server Gateway Interface (ASGI), a "spiritual successor to WSGI, intended to provide a standard interface between async-capable Python web servers, frameworks, and applications."

An ASGI app is a a double, asynchronous callable (scope and coroutine). The callable has send and receive awaitables, thus the ability to wait for incoming events and send outgoing events. Events essentially are dictionaries with a predefined format that form the basis of the standard.

Official ASGI documentation

212 questions
3
votes
1 answer

What is the correct way to configure asgi application & channels in djnago?

I've just started to learn about channels and asgi in django .... and in few tutorials that i've seen they do this to configure the asgi apllication asgi.py import os from django.core.asgi import get_asgi_application from channels.routing import…
py300
  • 51
  • 1
3
votes
0 answers

Django + uvicorn poor performance

I'm testing Django asgi performance using two very simple views. I'm running gunicorn and uvicorn in such a manner: gunicorn core.wsgi --workers=1 --threads=1 --access-logfile=- core.wsgi:application uvicorn --workers 1 core.asgi:application The…
MarcinSz
  • 31
  • 1
3
votes
1 answer

FastAPI: reject a WebSocket connection with HTTP response

In a FastAPI based Web app, I have a WebSocket endpoint that should allow connections only if some conditions are met, otherwise it should return an HTTP 404 reply instead of upgrading the connection with HTTP 101. As far as I understand, this is…
shevron
  • 3,463
  • 2
  • 23
  • 35
3
votes
2 answers

ERROR: Error loading ASGI app. Import string "main" must be in format ":"

Trying to test my first FastAPI application using uvicorn. The following code was written on Jupyter Notebook and saved as 'main.py' in the directory: /home/user from fastapi import FastAPI app = FastAPI() @app.get("/") async def root(): …
3
votes
1 answer

Django 3.1 asgi server timeout connecting to itself inside async view

Got an issue trying to connect from an async view in Django 3.1 to a sync view served by the same asgi server. Doing this in normal wsgi development server works, but not in an asgi server. Which seems kind of weird. Probably I misunderstood on how…
ephes
  • 1,451
  • 1
  • 13
  • 19
3
votes
1 answer

Django Channels 2: How Many Users Is In The Specific Room

I am using django-channels>=2.0.0 and I want to find how many users in "room1". I don't know how to find total connections.
John
  • 45
  • 1
  • 7
3
votes
2 answers

Django Channel 2 with Daphne on Heroku crash on starting

I created a django app using Channels 2 on heroku but it crash on starting with 503 error code. 2020-04-07T10:05:35.226253+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.mysite.com…
dubus_b
  • 31
  • 2
3
votes
1 answer

Django await on a function with @database_sync_to_async decorator for fetching multiple object throws error

I am integrating django channels for async capabilites. I am trying to fetch multiple objects of a user model using await on the function. consumers.py class TeamConsumer(AsyncConsumer): async def websocket_connect(self, event): await…
Arsh Doda
  • 294
  • 4
  • 14
3
votes
2 answers

FATAL: too many connections for role: Heroku/django, only while using ASGI

I know there are other similar questions but I believe I have gone through all of them but none of them was able to solve my problem. Everything is working fine when I am using WSGI server. It only happens when I use ASGI server however I must use…
Haris
  • 321
  • 3
  • 9
3
votes
1 answer

How to do client certificate verification (mTLS) in Starlette/FastAPI

I’m considering using FastAPI framework for implementing rather simple API, but it needs to support mTLS. AFAIK FastAPI is based on Starlette. Is it possible to check client certificate in Starlette?
Fedor
  • 1,392
  • 1
  • 17
  • 30
3
votes
2 answers

What's the difference between handling requests in Django 3 ASGI mode vs WSGI mode?

Django 3 should be released soon and it will be able to work in ASGI mode. ASGI mode seems to make Django more efficient when handling requests than in WSGI mode (more requests can be handled per time unit if I believe correctly). How is it…
eskaes
  • 75
  • 2
  • 5
3
votes
1 answer

How to fix the issue "django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet"?

I have deployed my django webapp to my heroku server and it was working fine until I added a websocket connection that shows the contents of a model object in a separate url as soon as that object is created. For this, I used Django channels with a…
Animesh Timsina
  • 386
  • 2
  • 10
3
votes
8 answers

Cannot import ASGI_APPLICATION module 'myproject.routing'

I've followed the channels 2 tutorial, but I'm getting this error after running py manage.py runserver File "C:\Users\Mach2\AppData\Local\Programs\Python\Python37-32\lib\site-packages\channels\routing.py", line 35, in get_default_application …
2
votes
1 answer

Websocket connection to failed on production host but it is fine in localhost django

I implemented websocket connection for live ubdation in by django application . The problem is it works in localhost but when i host the same application in public host server it not connecting .i used to host Daphne server droping my code down…
MansooR
  • 21
  • 1
2
votes
1 answer

How to unit test a pure ASGI middleware in python

I have an ASGI middleware that adds fields to the POST request body before it hits the route in my fastapi app. from starlette.types import ASGIApp, Message, Scope, Receive, Send class MyMiddleware: """ This middleware implements a raw ASGI…
tenticon
  • 2,639
  • 4
  • 32
  • 76