Django channels

266 views
Skip to first unread message

Алексей Кузуб

unread,
Feb 4, 2017, 5:41:11 AM2/4/17
to Django users
Hello! I'm using django channels. I deployed it in IIS 8 and it's work on http.request. But when I try to use websocket result is nothing. Daphne writes me "Websocket incoming frame on websocket.send!toke". Workers write me "Dispatching message on websocket.receive to channels.routing.null_consumer". Say me, please. What i'm doing wrong? 

Andrew Godwin

unread,
Feb 4, 2017, 7:12:30 PM2/4/17
to django...@googlegroups.com
"Dispatching message on websocket.receive to channels.routing.null_consumer" means that you don't have a consumer tied to the "websocket.receive" channel, so Channels is sending it nowhere. Did you set up your routing correctly?

Andrew

On Sat, Feb 4, 2017 at 2:41 AM, Алексей Кузуб <roni...@gmail.com> wrote:
Hello! I'm using django channels. I deployed it in IIS 8 and it's work on http.request. But when I try to use websocket result is nothing. Daphne writes me "Websocket incoming frame on websocket.send!toke". Workers write me "Dispatching message on websocket.receive to channels.routing.null_consumer". Say me, please. What i'm doing wrong? 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f67d74a0-fb8e-4d7e-abaa-e124befff531%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Алексей Кузуб

unread,
Feb 5, 2017, 3:55:47 PM2/5/17
to Django users
settings.py
redis_host = os.environ.get('REDIS_HOST', 'localhost')

CHANNEL_LAYERS
= {
   
'default': {
       
'BACKEND': 'asgi_redis.RedisChannelLayer',
       
'CONFIG': {
           
'hosts': [(redis_host, 6379)],
       
},
       
'ROUTING': 'VoteMagic.routing.channel_routing',
   
},
}

asgi.py
import os
from channels.asgi import get_channel_layer

os
.environ.setdefault("DJANGO_SETTINGS_MODULE", "VoteMagic.settings")

channel_layer
= get_channel_layer()

routing.py
from channels.routing import route
from votes.consumers import ws_message

channel_routing
= [
    route
("http.request", "votes.consumers.http_consumer"),
    route
("websocket.connect", ws_message),
    route
("websocket.receive", ws_message),
]

consumers.py
from django.http import HttpResponse
from channels.handler import AsgiHandler


def http_consumer(message):
    response
= HttpResponse("Hello world! You asked for %s" % message.content['path'])
   
for chunk in AsgiHandler.encode_response(response):
        message
.reply_channel.send(chunk)


def ws_message(message):
    message
.reply_channel.send({
       
"text": message.content['text'],
   
})

This is my code. And when I use http.request It's work! But when I try websockets result is nothing.



воскресенье, 5 февраля 2017 г., 3:12:30 UTC+3 пользователь Andrew Godwin написал:
"Dispatching message on websocket.receive to channels.routing.null_consumer" means that you don't have a consumer tied to the "websocket.receive" channel, so Channels is sending it nowhere. Did you set up your routing correctly?

Andrew
On Sat, Feb 4, 2017 at 2:41 AM, Алексей Кузуб <roni...@gmail.com> wrote:
Hello! I'm using django channels. I deployed it in IIS 8 and it's work on http.request. But when I try to use websocket result is nothing. Daphne writes me "Websocket incoming frame on websocket.send!toke". Workers write me "Dispatching message on websocket.receive to channels.routing.null_consumer". Say me, please. What i'm doing wrong? 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Andrew Godwin

unread,
Feb 5, 2017, 7:23:37 PM2/5/17
to django...@googlegroups.com
I'm surprised that's working, as you've tied `connect` to a consumer that is designed for `receive` messages - in particular, a `connect` message should not have a `text` key. Are you sure sockets are connecting alright?

If they are though, the rest looks like it should work. What versions of Channels/Daphne/Django/Python are you using?

Andrew 

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Алексей Кузуб

unread,
Feb 6, 2017, 2:52:57 AM2/6/17
to Django users
Websocket.connect does not work. Http.request works only. I try to use 'ws_message' with .connect to obtain some mistake. But no mistake was. Daphne writes me 
193.150.110.228:58244 - - [06/Feb/2017:10:42:04] "WSCONNECTING /" - -
2017-02-06 10:42:04,709 DEBUG    Upgraded connection http.response!hgLdPnoqcAkn
to WebSocket websocket.send!FlEitltfgsCC
2017-02-06 10:42:04,713 DEBUG    WebSocket websocket.send!FlEitltfgsCC open and
established
193.150.110.228:58244 - - [06/Feb/2017:10:42:04] "WSCONNECT /" - -
2017-02-06 10:42:04,714 DEBUG    WebSocket websocket.send!FlEitltfgsCC accepted
by application

Versions: Django 1.10.4, Python 3.5.2, Channels 1.0.2, Daphne 1.0.1. And another stack: Django 1.10.5, Python 3.6.0, Channels 1.0.3, Daphne 1.0.2.
Maybe it's some conflict with some apps like python-social-auth or Django REST Framework? Or maybe some problems with Redis? Can I check it?

понедельник, 6 февраля 2017 г., 3:23:37 UTC+3 пользователь Andrew Godwin написал:

Алексей Кузуб

unread,
Feb 6, 2017, 2:54:51 AM2/6/17
to Django users
And workers write me 
2017-02-06 10:42:04,709 - DEBUG - worker - Got message on websocket.connect (rep
ly websocket.send!FlEitltfgsCC)
2017-02-06 10:42:04,710 - DEBUG - runworker - websocket.connect
2017-02-06 10:42:04,711 - DEBUG - worker - Dispatching message on websocket.conn
ect to channels.routing.connect_consumer

Andrew Godwin

unread,
Feb 6, 2017, 12:34:03 PM2/6/17
to django...@googlegroups.com
The errors you're getting both point to Channels not using your second two routes, but I've tried a similar routing locally and it works fine for me. Is there a chance you could make this into a small sample project that reproduces the issue?

You could also try clearing any .pyc files or __pycache__ directories to make sure it's not some old code being cached, and making sure there's not a "routing" directory that clashes with routing.py

Andrew

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Алексей Кузуб

unread,
Feb 7, 2017, 9:51:43 AM2/7/17
to Django users
It works! I configure all from scratch step by step and it works! But I didn't find the reason of my problem. Maybe it was IIS or some Windows app =)
Thank you very much, Andrew! You really helped me.

понедельник, 6 февраля 2017 г., 20:34:03 UTC+3 пользователь Andrew Godwin написал:
The errors you're getting both point to Channels not using your second two routes, but I've tried a similar routing locally and it works fine for me. Is there a chance you could make this into a small sample project that reproduces the issue?

You could also try clearing any .pyc files or __pycache__ directories to make sure it's not some old code being cached, and making sure there's not a "routing" directory that clashes with routing.py

Andrew
On Sun, Feb 5, 2017 at 11:54 PM, Алексей Кузуб <roni...@gmail.com> wrote:
And workers write me 
2017-02-06 10:42:04,709 - DEBUG - worker - Got message on websocket.connect (rep
ly websocket.send!FlEitltfgsCC)
2017-02-06 10:42:04,710 - DEBUG - runworker - websocket.connect
2017-02-06 10:42:04,711 - DEBUG - worker - Dispatching message on websocket.conn
ect to channels.routing.connect_consumer

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages