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
