Unable to deploy the ASGI application with channels

Initially, I was using WSGI + gunicorn + nginx (as a load balancer) to deploy my application in a dockerized environment with python 3.9. Now I want to implement channels and socket io in the application.

In the development server (using runserver) the ASGI server is running fine. I can connect to both WebSockets and my HTTP endpoints but when I deploy it on the production server with docker + gunicorn + uvicon and nginx to proxy_pass connections to the http://web-app:5000 upstream, it is giving internal server error with the following error logs

[2021-12-09 18:53:35 +0000] [105] [ERROR] Exception in ASGI application
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 373, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/usr/local/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/channels/routing.py", line 71, in __call__
    return await application(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/asgiref/compatibility.py", line 34, in new_application
    instance = application(scope)
TypeError: 'tuple' object is not callable

And the following is my ASGI server configuration in the myweb.asgi.py file

import os
from django.core.asgi import get_asgi_application
from django import setup

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myweb.settings")
setup()

http = get_asgi_application(),

import routing
from channels.routing import ProtocolTypeRouter, URLRouter

application = ProtocolTypeRouter({
    "http": http,
    "websocket": URLRouter(routing.websocket_urlpatterns)
})

Django version 3.2.7

Channels versions: 3.0.4

Back to Top