Closed Schlepptop closed 5 years ago
What dependency versions? I have Django 1.11.15, daphne 2.2.3, and channels 2.1.2, and view kwargs works for me.
Django 2.1.4 channels 2.1.7 daphne 2.2.5
I just tried with your versions and it didn't work either. I must be doing something else wrong.
I just added the "chat2" example in this repository, based on Django 2. See if it works for you.
That does seem to somewhat work, although I don't understand how.
Somewhat, because when getting /default/events/ the app seems to receive a 200: connection open that then terminates, causing it to try and reconnect. Thus, the chatlog is just alternating between connected
and connection lost, reconnecting
.
But how does it even get that far? Where is the asgi app defined? And Where are the routing.py's? I seem to be missing something. Nonetheless, thank you very much for your help thus far.
Ah, since earlier you posted a urls.py
routing and mentioned not using Daphne, I thought you were using Pushpin so I didn't include the ASGI setup. Then I remembered Daphne is a dependency of channels and used by runserver (so you actually do use it even if you don't know it), and realized you probably have your route in the wrong place. I've added the ASGI setup to chat2 for reference.
I believe the main problem you're having is you need to put ASGI-related routes in routing.py
instead of urls.py
. You can put them in urls.py
as well, but only if you want the option of being able to run your app in WSGI mode with Pushpin. The chat example puts its routes in both files, which may have been confusing.
Separately, it seems there's a regression with channels >=2.1.6 and django_eventstream, so I've pinned it to 2.1.5 in the chat2 example. I'll look into resolving that.
Anyway, hopefully now if you use chat2 on a fresh virtualenv it'll just work.
Awesome, that did work! I didn't understand the relation between the urls.py and the routing.py. Thank you very much for your help and have a nice day.
One more thing: When deploying with channels, I just replace my gunicorn app.wsgi
with daphne app.asgi:application
. This seems to be wrong, as daphne does start and is supposedly listening, but no requests get handled.
I am deploying to dokku, if that is of relevance.
Could you tell me anything as to what my issue might be?
Added asgi.py file to chat2. Running daphne server.asgi:application
works for me.
That doesn't seem to work for me. Do I have to change anything else except for the gunicorn/daphne? Could my nginx be a problem? I pasted it here: https://gist.github.com/Schlepptop/40d7c9b8d24f6dca138a6c566f5387b9
Specifiying a bind address did the trick :slightly_smiling_face: Thanks for all your help.
I have defined a path as
path(r'recharge_room/dashboard/events/<int:pk>)', include(django_eventstream.urls), {'format-channels': ['room-{pk}']}),
in my project's urls.py. When trying to connect, I received a 200 response:{"condition": "bad-request", "text": "Invalid request: No channels specified."}
. Thus, I started looking for the issue. I let the DefaultChannelManager print the view_kwargs it receives forget_channels_for_request
, and they only include my pk. Does someone know what I am doing wrong? Any help would be greatly appreciated.