Django-Channels can't show exception error in console When an exception raise in any section of my consumer.
it just show "WebSocket DISCONNECT /ws/test/ [127.0.0.1:7907]" in console when exception occurred.
I run project with debug=True setting with this command:
python3 manage.py runserver
I use basic settings for django-channles:
# CHANNELS
# ------------------------------------------------------------------------------
ASGI_APPLICATION = "config.routing.application"
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
and have a very simple consumer for test:
class Test(WebsocketConsumer):
def connect(self):
print(self.scope['headers']) # show headers in console.
raise Exception('test exception') # this line doesn't show any thing in console. just show disconnect message.
self.accept()
def receive(self, text_data=None, bytes_data=None):
print(text_data)
and routing:
application = ProtocolTypeRouter({
'websocket': AuthMiddlewareStack(
URLRouter(
orders.routing.websocket_urlpatterns
)
),
})
I found the problem. Django channels can't log exceptions in console when i use debug_toolbar app. I removed debug_toolbar from INSTALLED_APPS and then the problem was solved.
this is my debug_toolbar configs:
# django-debug-toolbar
# ------------------------------------------------------------------------------
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#prerequisites
INSTALLED_APPS += ['debug_toolbar'] # noqa F405
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#middleware
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware'] # noqa F405
# https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config
DEBUG_TOOLBAR_CONFIG = {
'DISABLE_PANELS': [
'debug_toolbar.panels.redirects.RedirectsPanel',
],
'SHOW_TEMPLATE_CONTEXT': True,
}
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#internal-ips
INTERNAL_IPS = ['127.0.0.1', '10.0.2.2']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With