500 Internal Server Error Daphne HTTP processing error

I follow Channels’ docs and encountered an error thrown by daphne:

TypeError: __call__() missing 2 required positional arguments: ‘receive’ and ‘send’

Solution is suggested by Avinash-Raj, it worked for me.

Assign application in myproject/asgi.py like this:

from channels.routing import ProtocolTypeRouter


class CustomSocketioProtocolTypeRouter(ProtocolTypeRouter):
    """
    Overrided base class's __call__ method to support python socketio 4.2.0 and daphne 2.3.0
    """
    def __call__(self, scope, *args):
        if scope["type"] in self.application_mapping:
            handlerobj = self.application_mapping[scope["type"]](scope)
            if args:
                return handlerobj(*args)
            return handlerobj
        raise ValueError(
            "No application configured for scope type %r" % scope["type"]
        )

application = CustomSocketioProtocolTypeRouter({
    # (http->django views is added by default)
})

So following the tutorial add this

"websocket": AuthMiddlewareStack(
    URLRouter(
        chat.routing.websocket_urlpatterns
    )
),

To application:

application = CustomSocketioProtocolTypeRouter({
    # (http->django views is added by default)
    "websocket": AuthMiddlewareStack(
        URLRouter(
            chat.routing.websocket_urlpatterns
        )
    ),
})

Don’t try to add "http": get_asgi_application() !!!!! I swear to God!!!! Don’t!!! You will get this error again

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.