Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-26 Thread Mikhailo Keda

That post is outdated (it's not for Chanels 2), you nginx.conf is wrong, ws 
isn't location, it's protocol so you web sockets connections are forwarded 
to unix://myproject/experiment_platform.sock; and this triggers your error

You just need forward all connections to daphne (except /static)

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/08278657-b0c7-4bf7-8d08-6bb70ce24f26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-26 Thread Xiaoyun Huang
Thanks for your information!

I just did all the configurations again following this post(
http://masnun.rocks/2016/11/02/deploying-django-channels-using-daphne/).
And I think it is extremely useful for me and my website is now running.
And you are right, I don't need both uwsgi and daphne. Only daphne is
sufficient.

On Tue, Jun 26, 2018 at 10:47 PM, 赖信桃  wrote:

> Again, websocket is different from HTTP, both are built on TCP. So Nginx
> preoxy_pass is for HTTP forward, so you can not use it for HTTP for
> tanspond.
>
> Maybe remove location /ws would work. Just use daphne as ws server.
>
> Spend some time reading the docs: https://channels.
> readthedocs.io/en/latest/deploying.html
>
> 于2018年6月27日周三 上午10:09写道:
>
>> I think I must have messed the ports up. Here is a summary:
>>  redis: 6379
>> daphne: 8000 (if running daphne with this command: daphne
>> experiment_platform.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &)
>> ws (see *nginx.conf*): 8000 [I guess the error message in the browser
>> console "WebSocket connection to 'ws:///room1/' failed: Error
>> during WebSocket handshake: Unexpected response code: 200" means that I
>> did make a mistake in this nginx.conf, right?]
>>
>> Thanks.
>>
>> It occurs to me that posting the *nginx.conf* might be helpful:
>> upstream django {
>> server unix://myproject/experiment_platform.sock;
>> }
>> server{
>> listen 80;
>> server_name myproject;
>> charset utf-8;
>> client_max_body_size 20M;
>>
>> location /static {
>> alias myproject/static;
>> }
>>
>> location / {
>> include myproject/uwsgi_params;
>> uwsgi_pass unix://myproject/experiment_platform.sock;
>> }
>> location /ws {
>> proxy_pass http://0.0.0.0:8000;
>> proxy_http_version 1.1;
>> proxy_set_header Upgrade $http_upgrade;
>> proxy_set_header Connection "upgrade";
>> proxy_redirect off;
>> proxy_set_header   Host $host;
>> proxy_set_header   X-Real-IP $remote_addr;
>> proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
>> proxy_set_header   X-Forwarded-Host $server_name;
>> }
>> }
>>
>>
>> On Sunday, June 24, 2018 at 9:29:25 PM UTC-4, flora.xia...@gmail.com
>> wrote:
>>>
>>> Hi I am deploying a website with a live discussion feature. But people
>>> cannot send nor receive messages on this discussion page. In the console it
>>> shows: "WebSocket connection to 'ws:///room1/' failed: Error during
>>> WebSocket handshake: Unexpected response code: 200"
>>>
>>> I don't know where the websocket bug (or bugs from other sources) is. I
>>> am attaching some information that I think might be helpful. Could someone
>>> help? If you think I miss some information please let me know and I will
>>> post! Thanks!!
>>>
>>>
>>> *Server: ubuntu 14.03*
>>> *nginx*
>>> *commands to start the website:*
>>>  uwsgi --socket experiment_platform.sock --module
>>> experiment_platform.wsgi --chmod-socket=666 --processes=6
>>> daphne experiment_platform.asgi:channel_layer --port 8000 --bind
>>> 0.0.0.0 -v2 &
>>> python manage.py runworker -v2 &
>>> [redis server is also activated.]
>>>
>>> *log information of uwsgi (it keeps updating similar things after the
>>> discussion page is opened, whether or not I am trying to send messages to
>>> test or not. I think it's trying to establish the websocket connection.)*
>>> [pid: 29881|app: 0|req: 33/143] 100.15.133.125 () {52 vars in 1094
>>> bytes} [Mon Jun 25 01:23:59 2018] GET /forum/room1/ => generated 4792 bytes
>>> in 55 msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0)
>>> [pid: 29885|app: 0|req: 29/144] 100.15.133.125 () {52 vars in 1094 bytes}
>>> [Mon Jun 25 01:24:29 2018] GET /forum/room1/ => generated 4792 bytes in 57
>>> msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0)
>>>
>>> *log information of runworker (it doesn't update after opening the
>>> discussion page.)*
>>> 2018-06-25 00:22:42,827 - INFO - runworker - Running worker against
>>> channel layer default (asgi_redis.core.RedisChannelLayer)
>>> 2018-06-25 00:22:42,828 - INFO - worker - Listening on channels
>>> http.request, websocket.connect, websocket.disconnect, websocket.receive
>>>
>>> *forum/consumers.py*
>>> import re import json import logging from channels import Group from
>>> channels.sessions import channel_session from .models import Discussion,
>>> Statement, Vote from chat.models import Room from experiment.models import
>>> ExpUser,TaskUser, Crowd from channels.auth import http_session,
>>> http_session_user, channel_session_user, channel_session_user_from_http log
>>> = logging.getLogger(__name__) @channel_session_user_from_http
>>> @channel_session def ws_connect(message): # Extract the discussion-label
>>> from the message. This expects message.path to be of the # form
>>> forum/{label}/, and finds a Discussion if the message path is applicable, #
>>> and if the Discussion exists. Ot

Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-26 Thread 赖信桃
Again, websocket is different from HTTP, both are built on TCP. So Nginx
preoxy_pass is for HTTP forward, so you can not use it for HTTP for
tanspond.

Maybe remove location /ws would work. Just use daphne as ws server.

Spend some time reading the docs:
https://channels.readthedocs.io/en/latest/deploying.html

于2018年6月27日周三 上午10:09写道:

> I think I must have messed the ports up. Here is a summary:
>  redis: 6379
> daphne: 8000 (if running daphne with this command: daphne
> experiment_platform.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &)
> ws (see *nginx.conf*): 8000 [I guess the error message in the browser
> console "WebSocket connection to 'ws:///room1/' failed: Error
> during WebSocket handshake: Unexpected response code: 200" means that I
> did make a mistake in this nginx.conf, right?]
>
> Thanks.
>
> It occurs to me that posting the *nginx.conf* might be helpful:
> upstream django {
> server unix://myproject/experiment_platform.sock;
> }
> server{
> listen 80;
> server_name myproject;
> charset utf-8;
> client_max_body_size 20M;
>
> location /static {
> alias myproject/static;
> }
>
> location / {
> include myproject/uwsgi_params;
> uwsgi_pass unix://myproject/experiment_platform.sock;
> }
> location /ws {
> proxy_pass http://0.0.0.0:8000;
> proxy_http_version 1.1;
> proxy_set_header Upgrade $http_upgrade;
> proxy_set_header Connection "upgrade";
> proxy_redirect off;
> proxy_set_header   Host $host;
> proxy_set_header   X-Real-IP $remote_addr;
> proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_set_header   X-Forwarded-Host $server_name;
> }
> }
>
>
> On Sunday, June 24, 2018 at 9:29:25 PM UTC-4, flora.xia...@gmail.com
> wrote:
>>
>> Hi I am deploying a website with a live discussion feature. But people
>> cannot send nor receive messages on this discussion page. In the console it
>> shows: "WebSocket connection to 'ws:///room1/' failed: Error during
>> WebSocket handshake: Unexpected response code: 200"
>>
>> I don't know where the websocket bug (or bugs from other sources) is. I
>> am attaching some information that I think might be helpful. Could someone
>> help? If you think I miss some information please let me know and I will
>> post! Thanks!!
>>
>>
>> *Server: ubuntu 14.03*
>> *nginx*
>> *commands to start the website:*
>>  uwsgi --socket experiment_platform.sock --module
>> experiment_platform.wsgi --chmod-socket=666 --processes=6
>> daphne experiment_platform.asgi:channel_layer --port 8000 --bind 0.0.0.0
>> -v2 &
>> python manage.py runworker -v2 &
>> [redis server is also activated.]
>>
>> *log information of uwsgi (it keeps updating similar things after the
>> discussion page is opened, whether or not I am trying to send messages to
>> test or not. I think it's trying to establish the websocket connection.)*
>> [pid: 29881|app: 0|req: 33/143] 100.15.133.125 () {52 vars in 1094 bytes}
>> [Mon Jun 25 01:23:59 2018] GET /forum/room1/ => generated 4792 bytes in 55
>> msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0) [pid:
>> 29885|app: 0|req: 29/144] 100.15.133.125 () {52 vars in 1094 bytes} [Mon
>> Jun 25 01:24:29 2018] GET /forum/room1/ => generated 4792 bytes in 57 msecs
>> (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0)
>>
>> *log information of runworker (it doesn't update after opening the
>> discussion page.)*
>> 2018-06-25 00:22:42,827 - INFO - runworker - Running worker against
>> channel layer default (asgi_redis.core.RedisChannelLayer)
>> 2018-06-25 00:22:42,828 - INFO - worker - Listening on channels
>> http.request, websocket.connect, websocket.disconnect, websocket.receive
>>
>> *forum/consumers.py*
>> import re import json import logging from channels import Group from
>> channels.sessions import channel_session from .models import Discussion,
>> Statement, Vote from chat.models import Room from experiment.models import
>> ExpUser,TaskUser, Crowd from channels.auth import http_session,
>> http_session_user, channel_session_user, channel_session_user_from_http log
>> = logging.getLogger(__name__) @channel_session_user_from_http
>> @channel_session def ws_connect(message): # Extract the discussion-label
>> from the message. This expects message.path to be of the # form
>> forum/{label}/, and finds a Discussion if the message path is applicable, #
>> and if the Discussion exists. Otherwise, bails (meaning this is a some
>> othersort # of websocket). So, this is effectively a version of
>> _get_object_or_404. try: log.debug('In the try block of ws_connect')#added
>> by me prefix, label = message['path'].decode('ascii').strip('/').split('/')
>> if prefix != 'forum': log.debug('invalid ws path=%s', message['path'])
>> return if prefix == 'forum': discussion =
>> Discussion.objects.get(label=label) except ValueError: log.debug('invalid
>> ws path=%s', messag

Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-26 Thread flora . xiaoyun . huang
I think I must have messed the ports up. Here is a summary:
 redis: 6379
daphne: 8000 (if running daphne with this command: daphne 
experiment_platform.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &)
ws (see *nginx.conf*): 8000 [I guess the error message in the browser 
console "WebSocket connection to 'ws:///room1/' failed: Error 
during WebSocket handshake: Unexpected response code: 200" means that I did 
make a mistake in this nginx.conf, right?]

Thanks.

It occurs to me that posting the *nginx.conf* might be helpful:
upstream django {
server unix://myproject/experiment_platform.sock;
}
server{
listen 80;
server_name myproject;
charset utf-8;
client_max_body_size 20M;

location /static {
alias myproject/static;
}

location / {
include myproject/uwsgi_params;
uwsgi_pass unix://myproject/experiment_platform.sock;
}
location /ws {
proxy_pass http://0.0.0.0:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_set_header   Host $host;
proxy_set_header   X-Real-IP $remote_addr;
proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header   X-Forwarded-Host $server_name;
}
}


On Sunday, June 24, 2018 at 9:29:25 PM UTC-4, flora.xia...@gmail.com wrote:
>
> Hi I am deploying a website with a live discussion feature. But people 
> cannot send nor receive messages on this discussion page. In the console it 
> shows: "WebSocket connection to 'ws:///room1/' failed: Error during 
> WebSocket handshake: Unexpected response code: 200"
>
> I don't know where the websocket bug (or bugs from other sources) is. I am 
> attaching some information that I think might be helpful. Could someone 
> help? If you think I miss some information please let me know and I will 
> post! Thanks!!
>
>
> *Server: ubuntu 14.03*
> *nginx*
> *commands to start the website:*
>  uwsgi --socket experiment_platform.sock --module 
> experiment_platform.wsgi --chmod-socket=666 --processes=6
> daphne experiment_platform.asgi:channel_layer --port 8000 --bind 0.0.0.0 
> -v2 &
> python manage.py runworker -v2 &
> [redis server is also activated.]
>
> *log information of uwsgi (it keeps updating similar things after the 
> discussion page is opened, whether or not I am trying to send messages to 
> test or not. I think it's trying to establish the websocket connection.)*
> [pid: 29881|app: 0|req: 33/143] 100.15.133.125 () {52 vars in 1094 bytes} 
> [Mon Jun 25 01:23:59 2018] GET /forum/room1/ => generated 4792 bytes in 55 
> msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0) [pid: 
> 29885|app: 0|req: 29/144] 100.15.133.125 () {52 vars in 1094 bytes} [Mon 
> Jun 25 01:24:29 2018] GET /forum/room1/ => generated 4792 bytes in 57 msecs 
> (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0)
>
> *log information of runworker (it doesn't update after opening the 
> discussion page.)*
> 2018-06-25 00:22:42,827 - INFO - runworker - Running worker against 
> channel layer default (asgi_redis.core.RedisChannelLayer)
> 2018-06-25 00:22:42,828 - INFO - worker - Listening on channels 
> http.request, websocket.connect, websocket.disconnect, websocket.receive
>
> *forum/consumers.py*
> import re import json import logging from channels import Group from 
> channels.sessions import channel_session from .models import Discussion, 
> Statement, Vote from chat.models import Room from experiment.models import 
> ExpUser,TaskUser, Crowd from channels.auth import http_session, 
> http_session_user, channel_session_user, channel_session_user_from_http log 
> = logging.getLogger(__name__) @channel_session_user_from_http 
> @channel_session def ws_connect(message): # Extract the discussion-label 
> from the message. This expects message.path to be of the # form 
> forum/{label}/, and finds a Discussion if the message path is applicable, # 
> and if the Discussion exists. Otherwise, bails (meaning this is a some 
> othersort # of websocket). So, this is effectively a version of 
> _get_object_or_404. try: log.debug('In the try block of ws_connect')#added 
> by me prefix, label = message['path'].decode('ascii').strip('/').split('/') 
> if prefix != 'forum': log.debug('invalid ws path=%s', message['path']) 
> return if prefix == 'forum': discussion = 
> Discussion.objects.get(label=label) except ValueError: log.debug('invalid 
> ws path=%s', message['path']) return except Discussion.DoesNotExist: 
> log.debug('ws discussion does not exist label=%s', label) return if prefix 
> == 'forum': log.debug('forum connect discussion=%s client=%s:%s', 
> discussion.label, message['client'][0], message['client'][1]) t = 
> TaskUser(user=message.user,crowd=label,time_type='start') t.save() # Need 
> to be explicit about the channel layer so that testability works # This may 
> be a FIXME? Group

Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-25 Thread flora . xiaoyun . huang
Oh... I'd better not change the framework of my website. Do you have any 
ideas about the bug based on the existing information I provide?

On Monday, June 25, 2018 at 12:35:58 PM UTC-4, Mikhailo Keda wrote:
>
> yea, why not?
>
> I'm using daphne with supervisord + Nginx
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/aa104f4d-086a-4668-8ede-2ca28590956b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-25 Thread Mikhailo Keda
yea, why not?

I'm using daphne with supervisord + Nginx

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/f469d8ad-26ec-4d60-834a-cf9569abf1bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-25 Thread flora . xiaoyun . huang
Are you referring to only using daphne command? I cannot get my website 
running with only this command.

On Monday, June 25, 2018 at 11:55:01 AM UTC-4, Mikhailo Keda wrote:
>
> no, for Channels 2 you need one command
> https://channels.readthedocs.io/en/latest/deploying.html
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/c7179a4e-2200-4772-888a-8fd17a9e9006%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-25 Thread Mikhailo Keda
no, for Channels 2 you need one command
https://channels.readthedocs.io/en/latest/deploying.html

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/cd13c219-8861-4e15-9d9f-eb9bd961779e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-25 Thread flora . xiaoyun . huang
So you mean I need these two commands to get my website running. Do you 
notice something unusual from the log info of uwsgi and daphne?


On Monday, June 25, 2018 at 11:36:00 AM UTC-4, laixintao wrote:
>
> No, runserver is for web development, and runworker is for channel (AKA 
> websocket) development.
>
> And in production, you need uWSGI for runserver and daphne for runworker.
>
> >于2018年6月25日周一 下午11:21写道:
>
>> Thanks for your reply. But I am afraid this is not the problem. The urls 
>> are dispatched correctly. Different pages of my website can be directed 
>> correctly. 
>> The live discussion is just one function on one page. Other parts of this 
>> page are functioning well. 
>>
>>
>> On Monday, June 25, 2018 at 10:55:37 AM UTC-4, Mikhailo Keda wrote:
>>>
>>> probably you added this path /forum/room1/ to urls.py, you need to add 
>>> this path to routing 
>>> https://channels.readthedocs.io/en/latest/topics/routing.html
>>>
>> -- 
>> 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.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/e649c167-9087-4273-8519-607f507812ed%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/e31fb003-4648-4649-98da-75fd589246cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-25 Thread 赖信桃
No, runserver is for web development, and runworker is for channel (AKA
websocket) development.

And in production, you need uWSGI for runserver and daphne for runworker.

于2018年6月25日周一 下午11:21写道:

> Thanks for your reply. But I am afraid this is not the problem. The urls
> are dispatched correctly. Different pages of my website can be directed
> correctly.
> The live discussion is just one function on one page. Other parts of this
> page are functioning well.
>
>
> On Monday, June 25, 2018 at 10:55:37 AM UTC-4, Mikhailo Keda wrote:
>>
>> probably you added this path /forum/room1/ to urls.py, you need to add
>> this path to routing
>> https://channels.readthedocs.io/en/latest/topics/routing.html
>>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@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/e649c167-9087-4273-8519-607f507812ed%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/CAMv51WQn-vFgd9xT5AeyC8-XTE9unf%2BrDzi5UwZDT4tdiwOq-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-25 Thread flora . xiaoyun . huang
Thanks for your reply. But I am afraid this is not the problem. The urls 
are dispatched correctly. Different pages of my website can be directed 
correctly. 
The live discussion is just one function on one page. Other parts of this 
page are functioning well. 

On Monday, June 25, 2018 at 10:55:37 AM UTC-4, Mikhailo Keda wrote:
>
> probably you added this path /forum/room1/ to urls.py, you need to add 
> this path to routing 
> https://channels.readthedocs.io/en/latest/topics/routing.html
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/e649c167-9087-4273-8519-607f507812ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-25 Thread flora . xiaoyun . huang
Thanks for your reply. 

Here is the log information of daphne:
 2018-06-25 15:12:38,199 INFO Starting server at 
tcp:port=8000:interface=0.0.0.0, channel layer 
experiment_platform.asgi:channel_layer.
 2018-06-25 15:12:38,200 INFO HTTP/2 support not enabled (install 
the http2 and tls Twisted extras)
 2018-06-25 15:12:38,200 INFO Using busy-loop synchronous mode on 
channel layer
 2018-06-25 15:12:38,201 INFO Listening on endpoint 
tcp:port=8000:interface=0.0.0.0
 2018-06-25 15:12:38,201 INFO HTTPFactory starting on 8000
 2018-06-25 15:12:38,202 INFO Starting factory 

> I haven't use Django's channel yet, but I guess that you route your url in 
> a wrong way. Somehow your websocket connection goes to your uWSGI server, 
> it should goes to your daphne server.
>
> Did your daphne receive any connection request?
>
> And you shouldn't use this on server:
>
> python manage.py runworker -v2 &
>
> It's for development use, I think. In your server you use uWSGI as HTTP 
> server and daphne as websocket server.
>
> >于2018年6月25日周一 上午9:29写道:
>
>> Hi I am deploying a website with a live discussion feature. But people 
>> cannot send nor receive messages on this discussion page. In the console it 
>> shows: "WebSocket connection to 'ws:///room1/' failed: Error during 
>> WebSocket handshake: Unexpected response code: 200"
>>
>> I don't know where the websocket bug (or bugs from other sources) is. I 
>> am attaching some information that I think might be helpful. Could someone 
>> help? If you think I miss some information please let me know and I will 
>> post! Thanks!!
>>
>>
>> *Server: ubuntu 14.03*
>> *nginx*
>> *commands to start the website:*
>>  uwsgi --socket experiment_platform.sock --module 
>> experiment_platform.wsgi --chmod-socket=666 --processes=6
>> daphne experiment_platform.asgi:channel_layer --port 8000 --bind 0.0.0.0 
>> -v2 &
>> python manage.py runworker -v2 &
>> [redis server is also activated.]
>>
>> *log information of uwsgi (it keeps updating similar things after the 
>> discussion page is opened, whether or not I am trying to send messages to 
>> test or not. I think it's trying to establish the websocket connection.)*
>> [pid: 29881|app: 0|req: 33/143] 100.15.133.125 () {52 vars in 1094 bytes} 
>> [Mon Jun 25 01:23:59 2018] GET /forum/room1/ => generated 4792 bytes in 55 
>> msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0) [pid: 
>> 29885|app: 0|req: 29/144] 100.15.133.125 () {52 vars in 1094 bytes} [Mon 
>> Jun 25 01:24:29 2018] GET /forum/room1/ => generated 4792 bytes in 57 msecs 
>> (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0)
>>
>> *log information of runworker (it doesn't update after opening the 
>> discussion page.)*
>> 2018-06-25 00:22:42,827 - INFO - runworker - Running worker against 
>> channel layer default (asgi_redis.core.RedisChannelLayer)
>> 2018-06-25 00:22:42,828 - INFO - worker - Listening on channels 
>> http.request, websocket.connect, websocket.disconnect, websocket.receive
>>
>> *forum/consumers.py*
>> import re import json import logging from channels import Group from 
>> channels.sessions import channel_session from .models import Discussion, 
>> Statement, Vote from chat.models import Room from experiment.models import 
>> ExpUser,TaskUser, Crowd from channels.auth import http_session, 
>> http_session_user, channel_session_user, channel_session_user_from_http log 
>> = logging.getLogger(__name__) @channel_session_user_from_http 
>> @channel_session def ws_connect(message): # Extract the discussion-label 
>> from the message. This expects message.path to be of the # form 
>> forum/{label}/, and finds a Discussion if the message path is applicable, # 
>> and if the Discussion exists. Otherwise, bails (meaning this is a some 
>> othersort # of websocket). So, this is effectively a version of 
>> _get_object_or_404. try: log.debug('In the try block of ws_connect')#added 
>> by me prefix, label = message['path'].decode('ascii').strip('/').split('/') 
>> if prefix != 'forum': log.debug('invalid ws path=%s', message['path']) 
>> return if prefix == 'forum': discussion = 
>> Discussion.objects.get(label=label) except ValueError: log.debug('invalid 
>> ws path=%s', message['path']) return except Discussion.DoesNotExist: 
>> log.debug('ws discussion does not exist label=%s', label) return if prefix 
>> == 'forum': log.debug('forum connect discussion=%s client=%s:%s', 
>> discussion.label, message['client'][0], message['client'][1]) t = 
>> TaskUser(user=message.user,crowd=label,time_type='start') t.save() # Need 
>> to be explicit about the channel layer so that testability works # This may 
>> be a FIXME? Group('forum-'+label, 
>> channel_layer=message.channel_layer).add(message.reply_channel) 
>> message.channel_session['discussion'] = discussion.label 
>> message.reply_channel.send({ 'accept': True }) @channel_session_user 
>> @channel_session def ws_receive(message): if '

Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-25 Thread Mikhailo Keda
probably you added this path /forum/room1/ to urls.py, you need to add this 
path to routing 
https://channels.readthedocs.io/en/latest/topics/routing.html

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/16c766dd-6b44-4830-999c-27d68bbe93dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-25 Thread 赖信桃
I haven't use Django's channel yet, but I guess that you route your url in
a wrong way. Somehow your websocket connection goes to your uWSGI server,
it should goes to your daphne server.

Did your daphne receive any connection request?

And you shouldn't use this on server:

python manage.py runworker -v2 &

It's for development use, I think. In your server you use uWSGI as HTTP
server and daphne as websocket server.

于2018年6月25日周一 上午9:29写道:

> Hi I am deploying a website with a live discussion feature. But people
> cannot send nor receive messages on this discussion page. In the console it
> shows: "WebSocket connection to 'ws:///room1/' failed: Error during
> WebSocket handshake: Unexpected response code: 200"
>
> I don't know where the websocket bug (or bugs from other sources) is. I am
> attaching some information that I think might be helpful. Could someone
> help? If you think I miss some information please let me know and I will
> post! Thanks!!
>
>
> *Server: ubuntu 14.03*
> *nginx*
> *commands to start the website:*
>  uwsgi --socket experiment_platform.sock --module
> experiment_platform.wsgi --chmod-socket=666 --processes=6
> daphne experiment_platform.asgi:channel_layer --port 8000 --bind 0.0.0.0
> -v2 &
> python manage.py runworker -v2 &
> [redis server is also activated.]
>
> *log information of uwsgi (it keeps updating similar things after the
> discussion page is opened, whether or not I am trying to send messages to
> test or not. I think it's trying to establish the websocket connection.)*
> [pid: 29881|app: 0|req: 33/143] 100.15.133.125 () {52 vars in 1094 bytes}
> [Mon Jun 25 01:23:59 2018] GET /forum/room1/ => generated 4792 bytes in 55
> msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0) [pid:
> 29885|app: 0|req: 29/144] 100.15.133.125 () {52 vars in 1094 bytes} [Mon
> Jun 25 01:24:29 2018] GET /forum/room1/ => generated 4792 bytes in 57 msecs
> (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0)
>
> *log information of runworker (it doesn't update after opening the
> discussion page.)*
> 2018-06-25 00:22:42,827 - INFO - runworker - Running worker against
> channel layer default (asgi_redis.core.RedisChannelLayer)
> 2018-06-25 00:22:42,828 - INFO - worker - Listening on channels
> http.request, websocket.connect, websocket.disconnect, websocket.receive
>
> *forum/consumers.py*
> import re import json import logging from channels import Group from
> channels.sessions import channel_session from .models import Discussion,
> Statement, Vote from chat.models import Room from experiment.models import
> ExpUser,TaskUser, Crowd from channels.auth import http_session,
> http_session_user, channel_session_user, channel_session_user_from_http log
> = logging.getLogger(__name__) @channel_session_user_from_http
> @channel_session def ws_connect(message): # Extract the discussion-label
> from the message. This expects message.path to be of the # form
> forum/{label}/, and finds a Discussion if the message path is applicable, #
> and if the Discussion exists. Otherwise, bails (meaning this is a some
> othersort # of websocket). So, this is effectively a version of
> _get_object_or_404. try: log.debug('In the try block of ws_connect')#added
> by me prefix, label = message['path'].decode('ascii').strip('/').split('/')
> if prefix != 'forum': log.debug('invalid ws path=%s', message['path'])
> return if prefix == 'forum': discussion =
> Discussion.objects.get(label=label) except ValueError: log.debug('invalid
> ws path=%s', message['path']) return except Discussion.DoesNotExist:
> log.debug('ws discussion does not exist label=%s', label) return if prefix
> == 'forum': log.debug('forum connect discussion=%s client=%s:%s',
> discussion.label, message['client'][0], message['client'][1]) t =
> TaskUser(user=message.user,crowd=label,time_type='start') t.save() # Need
> to be explicit about the channel layer so that testability works # This may
> be a FIXME? Group('forum-'+label,
> channel_layer=message.channel_layer).add(message.reply_channel)
> message.channel_session['discussion'] = discussion.label
> message.reply_channel.send({ 'accept': True }) @channel_session_user
> @channel_session def ws_receive(message): if 'discussion' in
> message.channel_session: # Look up the room from the channel session,
> bailing if it doesn't exist try: label =
> message.channel_session['discussion'] discussion =
> Discussion.objects.get(label=label) except KeyError: log.debug('no
> discussion-forum in channel_session') return except
> Discussion.DoesNotExist: log.debug('recieved message, buy discussion does
> not exist label=%s', label) return try: expuser =
> ExpUser.objects.get(user=message.user) except KeyError: log.debug('problem
> getting username') return except ExpUser.DoesNotExist: log.debug('recieved
> message, but user does not exist label=%s', label) return # Parse out a
> chat message from the content text, bailing if it doesn't # conform to the
> expected message forma

Websocket connection failed: Error during WebSocket handshake: Unexpected response code: 200

2018-06-24 Thread flora . xiaoyun . huang
Hi I am deploying a website with a live discussion feature. But people 
cannot send nor receive messages on this discussion page. In the console it 
shows: "WebSocket connection to 'ws:///room1/' failed: Error during 
WebSocket handshake: Unexpected response code: 200"

I don't know where the websocket bug (or bugs from other sources) is. I am 
attaching some information that I think might be helpful. Could someone 
help? If you think I miss some information please let me know and I will 
post! Thanks!!


*Server: ubuntu 14.03*
*nginx*
*commands to start the website:*
 uwsgi --socket experiment_platform.sock --module 
experiment_platform.wsgi --chmod-socket=666 --processes=6
daphne experiment_platform.asgi:channel_layer --port 8000 --bind 0.0.0.0 
-v2 &
python manage.py runworker -v2 &
[redis server is also activated.]

*log information of uwsgi (it keeps updating similar things after the 
discussion page is opened, whether or not I am trying to send messages to 
test or not. I think it's trying to establish the websocket connection.)*
[pid: 29881|app: 0|req: 33/143] 100.15.133.125 () {52 vars in 1094 bytes} 
[Mon Jun 25 01:23:59 2018] GET /forum/room1/ => generated 4792 bytes in 55 
msecs (HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0) [pid: 
29885|app: 0|req: 29/144] 100.15.133.125 () {52 vars in 1094 bytes} [Mon 
Jun 25 01:24:29 2018] GET /forum/room1/ => generated 4792 bytes in 57 msecs 
(HTTP/1.1 200) 3 headers in 102 bytes (1 switches on core 0)

*log information of runworker (it doesn't update after opening the 
discussion page.)*
2018-06-25 00:22:42,827 - INFO - runworker - Running worker against channel 
layer default (asgi_redis.core.RedisChannelLayer)
2018-06-25 00:22:42,828 - INFO - worker - Listening on channels 
http.request, websocket.connect, websocket.disconnect, websocket.receive

*forum/consumers.py*
import re import json import logging from channels import Group from 
channels.sessions import channel_session from .models import Discussion, 
Statement, Vote from chat.models import Room from experiment.models import 
ExpUser,TaskUser, Crowd from channels.auth import http_session, 
http_session_user, channel_session_user, channel_session_user_from_http log 
= logging.getLogger(__name__) @channel_session_user_from_http 
@channel_session def ws_connect(message): # Extract the discussion-label 
from the message. This expects message.path to be of the # form 
forum/{label}/, and finds a Discussion if the message path is applicable, # 
and if the Discussion exists. Otherwise, bails (meaning this is a some 
othersort # of websocket). So, this is effectively a version of 
_get_object_or_404. try: log.debug('In the try block of ws_connect')#added 
by me prefix, label = message['path'].decode('ascii').strip('/').split('/') 
if prefix != 'forum': log.debug('invalid ws path=%s', message['path']) 
return if prefix == 'forum': discussion = 
Discussion.objects.get(label=label) except ValueError: log.debug('invalid 
ws path=%s', message['path']) return except Discussion.DoesNotExist: 
log.debug('ws discussion does not exist label=%s', label) return if prefix 
== 'forum': log.debug('forum connect discussion=%s client=%s:%s', 
discussion.label, message['client'][0], message['client'][1]) t = 
TaskUser(user=message.user,crowd=label,time_type='start') t.save() # Need 
to be explicit about the channel layer so that testability works # This may 
be a FIXME? Group('forum-'+label, 
channel_layer=message.channel_layer).add(message.reply_channel) 
message.channel_session['discussion'] = discussion.label 
message.reply_channel.send({ 'accept': True }) @channel_session_user 
@channel_session def ws_receive(message): if 'discussion' in 
message.channel_session: # Look up the room from the channel session, 
bailing if it doesn't exist try: label = 
message.channel_session['discussion'] discussion = 
Discussion.objects.get(label=label) except KeyError: log.debug('no 
discussion-forum in channel_session') return except 
Discussion.DoesNotExist: log.debug('recieved message, buy discussion does 
not exist label=%s', label) return try: expuser = 
ExpUser.objects.get(user=message.user) except KeyError: log.debug('problem 
getting username') return except ExpUser.DoesNotExist: log.debug('recieved 
message, but user does not exist label=%s', label) return # Parse out a 
chat message from the content text, bailing if it doesn't # conform to the 
expected message format. try: data = json.loads(message['text']) except 
ValueError: log.debug("ws message isn't json text=%s", text) return if 
data: if data['msg_type'] == 'vote': log.debug('vote handle=%s value=%s', 
expuser.nickname, data['value']) statement = 
Statement.objects.get(id=data['id']) m0 = statement.as_dict() 
log.debug('vote id=%s, score=%s, ups=%s, 
downs=%s',statement.id,statement.score,statement.ups,statement.downs) ndata 
= 
{'user':message.user,'handle':expuser.nickname,'statement':statement,'value':data['value']}
 
vote = None votes