url routing correct locally but doesn't work on server

2019-02-21 Thread flora . xiaoyun . huang
Hi everyone. The problem I came across is that the url routing is correct 
locally but not on the server. The urls.py and views.py are the same 
locally and on the server.

For example after we enter the website link the first page of the website 
should be directed to *xxx.com/consent_form*, which has been made clear in 
function *consent_form* in the *views.py *under the corresponding app 
folder *app_name**. *
When we test locally after we enter 127.0.0.1:8000/ the page is directed 
correctly to 127.0.0.1:8000/consent_form. But when we deploy on the server 
and test by entering xxx.com the first page of the website is* 
xxx.com/app_name.views.consent_form*.

Anyone know what the problem might be? We are using nginx+daphne+django to 
deploy the website.






-- 
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/b78b6967-50d9-4080-ac23-8068ae9c91cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket 200 error

2019-02-19 Thread flora . xiaoyun . huang
The redis issue solved, by revising redis configuration: config set 
stop-writes-on-bgsave-error no
And the redis server can be restarted.

On Monday, February 18, 2019 at 9:19:52 PM UTC-5, flora.xia...@gmail.com 
wrote:
>
> I am guessing maybe there is an issue with the redis-server? *The log I 
> received from Daphne*:
> 2019-02-18 21:07:54,543 ERRORError trying to receive messages: Error 
> running script (call to f_3640886a0c8901ca9188f5f7a5f7a346145b9c5f): 
> @user_script:3: @user_script: 3: -MISCONF Redis is configured to save RDB 
> snapshots, but is currently not able to persist on disk. Commands that may 
> modify the data set are disabled. Please check Redis logs for details about 
> the error.
>
> So I check *redis log*:
> [1418] 18 Feb 16:09:27.071 * 1 changes in 900 seconds. Saving...
> [1418] 18 Feb 16:09:27.072 * Background saving started by pid 2834
> [2834] 18 Feb 16:09:27.073 # Failed opening .rdb for saving: Permission 
> denied
> [1418] 18 Feb 16:09:27.172 # Background saving error
>
> I searched ways to solve the problem and set the permission of .rdb to 
> 777. But still has this error in redis log.
>
> I also find I cannot shutdown and restart redis. 
>
> When I type redis-server in the command line, the log info:
> [2892] 18 Feb 16:14:32.457 # Warning: no config file specified, using the 
> default config. In order to specify a config file use redis-server 
> /path/to/redis.conf
> [2892] 18 Feb 16:14:32.459 # Unable to set the max number of files limit 
> to 10032 (Operation not permitted), setting the max clients configuration 
> to 3984.
> [2892] 18 Feb 16:14:32.459 # Creating Server TCP listening socket *:6379: 
> bind: Address already in use
>
> *These are the redis processes running:*
> redis-ser  1418redis4u  IPv6  14515  0t0  TCP *:6379 (LISTEN)
> redis-ser  1418redis5u  IPv4  14516  0t0  TCP *:6379 (LISTEN)
> redis-ser  1418redis6u  IPv6 203617  0t0  TCP 
> localhost:6379->localhost:34108 (ESTABLISHED)
> redis-ser  1418redis7u  IPv6 202944  0t0  TCP 
> localhost:6379->localhost:34104 (ESTABLISHED)
>
> On Monday, February 18, 2019 at 4:14:44 PM UTC-5, flora.xia...@gmail.com 
> wrote:
>>
>> Hi,
>>
>> The real-time discussion function (supported by Daphne) on my website is 
>> not working (Other non-real-time functions are good). The console echos: 
>> "WebSocket connection to 'ws://xxxforum/room_xxx/' failed: Error during 
>> WebSocket handshake: Unexpected response code: 200". I've went through the 
>> blog posts and the documentation but couldn't find a solution. Can anyone 
>> help?
>>
>> I am attaching information that I think is needed. If you need any other 
>> information please let me know.
>>
>> *The non-real-time part is supported by uwsgi* (I know it can be 
>> supported by Daphne too. But since the real-time part is not working I 
>> decide to use uwsgi): 
>> uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=666 
>> --processes=6
>>
>> *daphne*:
>> daphne mysite.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &
>> python manage.py runworker -v2 &
>>
>> *nginx configuration:*
>> upstream websocket { server 0.0.0.0:8000; } server { listen 80; 
>> server_name mysite.com; charset utf-8; client_max_body_size 20M; 
>> location /static { alias /path/to/mysite/static; } location / { include 
>> /etc/nginx/uwsgi_params;
>> uwsgi_pass unix:///path/to/mysite/mysite.sock; } location /ws { 
>> proxy_pass http://websocket; 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;
>> }
>> }
>>
>> One thing that I don't understand is that if I try to use Daphne to 
>> support both real-time and non-real-time communication by deleting the 
>> uwsgi block "location / {}" and renaming "location /ws {}" to "location / 
>> {}" the nginx service cannot be restarted. Does it suggest any bug?
>>
>> *first few lines in .js related to the discussion function:*
>> $(function() {
>> var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws"; var 
>> chatsock = new ReconnectingWebSocket(ws_scheme + '://' + 
>> window.location.host + window.location.pathname);
>> ..
>>
>>

-- 
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/3d5da9eb-ce85-4924-bd46-e28f4ed8ede0%40googlegroups.com.
For more 

Re: Websocket 200 error

2019-02-18 Thread flora . xiaoyun . huang
I am guessing maybe there is an issue with the redis-server? *The log I 
received from Daphne*:
2019-02-18 21:07:54,543 ERRORError trying to receive messages: Error 
running script (call to f_3640886a0c8901ca9188f5f7a5f7a346145b9c5f): 
@user_script:3: @user_script: 3: -MISCONF Redis is configured to save RDB 
snapshots, but is currently not able to persist on disk. Commands that may 
modify the data set are disabled. Please check Redis logs for details about 
the error.

So I check *redis log*:
[1418] 18 Feb 16:09:27.071 * 1 changes in 900 seconds. Saving...
[1418] 18 Feb 16:09:27.072 * Background saving started by pid 2834
[2834] 18 Feb 16:09:27.073 # Failed opening .rdb for saving: Permission 
denied
[1418] 18 Feb 16:09:27.172 # Background saving error

I searched ways to solve the problem and set the permission of .rdb to 777. 
But still has this error in redis log.

I also find I cannot shutdown and restart redis. 

When I type redis-server in the command line, the log info:
[2892] 18 Feb 16:14:32.457 # Warning: no config file specified, using the 
default config. In order to specify a config file use redis-server 
/path/to/redis.conf
[2892] 18 Feb 16:14:32.459 # Unable to set the max number of files limit to 
10032 (Operation not permitted), setting the max clients configuration to 
3984.
[2892] 18 Feb 16:14:32.459 # Creating Server TCP listening socket *:6379: 
bind: Address already in use

*These are the redis processes running:*
redis-ser  1418redis4u  IPv6  14515  0t0  TCP *:6379 (LISTEN)
redis-ser  1418redis5u  IPv4  14516  0t0  TCP *:6379 (LISTEN)
redis-ser  1418redis6u  IPv6 203617  0t0  TCP 
localhost:6379->localhost:34108 (ESTABLISHED)
redis-ser  1418redis7u  IPv6 202944  0t0  TCP 
localhost:6379->localhost:34104 (ESTABLISHED)

On Monday, February 18, 2019 at 4:14:44 PM UTC-5, flora.xia...@gmail.com 
wrote:
>
> Hi,
>
> The real-time discussion function (supported by Daphne) on my website is 
> not working (Other non-real-time functions are good). The console echos: 
> "WebSocket connection to 'ws://xxxforum/room_xxx/' failed: Error during 
> WebSocket handshake: Unexpected response code: 200". I've went through the 
> blog posts and the documentation but couldn't find a solution. Can anyone 
> help?
>
> I am attaching information that I think is needed. If you need any other 
> information please let me know.
>
> *The non-real-time part is supported by uwsgi* (I know it can be 
> supported by Daphne too. But since the real-time part is not working I 
> decide to use uwsgi): 
> uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=666 
> --processes=6
>
> *daphne*:
> daphne mysite.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &
> python manage.py runworker -v2 &
>
> *nginx configuration:*
> upstream websocket { server 0.0.0.0:8000; } server { listen 80; 
> server_name mysite.com; charset utf-8; client_max_body_size 20M; location 
> /static { alias /path/to/mysite/static; } location / { include 
> /etc/nginx/uwsgi_params;
> uwsgi_pass unix:///path/to/mysite/mysite.sock; } location /ws { proxy_pass 
> http://websocket; 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;
> }
> }
>
> One thing that I don't understand is that if I try to use Daphne to 
> support both real-time and non-real-time communication by deleting the 
> uwsgi block "location / {}" and renaming "location /ws {}" to "location / 
> {}" the nginx service cannot be restarted. Does it suggest any bug?
>
> *first few lines in .js related to the discussion function:*
> $(function() {
> var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws"; var 
> chatsock = new ReconnectingWebSocket(ws_scheme + '://' + 
> window.location.host + window.location.pathname);
> ..
>
>

-- 
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/4886f1be-5177-405b-9b90-43603db779ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Websocket 200 error

2019-02-18 Thread flora . xiaoyun . huang
Thank you in advance!

On Monday, February 18, 2019 at 4:14:44 PM UTC-5, flora.xia...@gmail.com 
wrote:
>
> Hi,
>
> The real-time discussion function (supported by Daphne) on my website is 
> not working (Other non-real-time functions are good). The console echos: 
> "WebSocket connection to 'ws://xxxforum/room_xxx/' failed: Error during 
> WebSocket handshake: Unexpected response code: 200". I've went through the 
> blog posts and the documentation but couldn't find a solution. Can anyone 
> help?
>
> I am attaching information that I think is needed. If you need any other 
> information please let me know.
>
> *The non-real-time part is supported by uwsgi* (I know it can be 
> supported by Daphne too. But since the real-time part is not working I 
> decide to use uwsgi): 
> uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=666 
> --processes=6
>
> *daphne*:
> daphne mysite.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &
> python manage.py runworker -v2 &
>
> *nginx configuration:*
> upstream websocket { server 0.0.0.0:8000; } server { listen 80; 
> server_name mysite.com; charset utf-8; client_max_body_size 20M; location 
> /static { alias /path/to/mysite/static; } location / { include 
> /etc/nginx/uwsgi_params;
> uwsgi_pass unix:///path/to/mysite/mysite.sock; } location /ws { proxy_pass 
> http://websocket; 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;
> }
> }
>
> One thing that I don't understand is that if I try to use Daphne to 
> support both real-time and non-real-time communication by deleting the 
> uwsgi block "location / {}" and renaming "location /ws {}" to "location / 
> {}" the nginx service cannot be restarted. Does it suggest any bug?
>
> *first few lines in .js related to the discussion function:*
> $(function() {
> var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws"; var 
> chatsock = new ReconnectingWebSocket(ws_scheme + '://' + 
> window.location.host + window.location.pathname);
> ..
>
>

-- 
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/2bf2a20d-2650-49e6-a9e3-f0602b498a0a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Websocket 200 error

2019-02-18 Thread flora . xiaoyun . huang
Hi,

The real-time discussion function (supported by Daphne) on my website is 
not working (Other non-real-time functions are good). The console echos: 
"WebSocket connection to 'ws://xxxforum/room_xxx/' failed: Error during 
WebSocket handshake: Unexpected response code: 200". I've went through the 
blog posts and the documentation but couldn't find a solution. Can anyone 
help?

I am attaching information that I think is needed. If you need any other 
information please let me know.

*The non-real-time part is supported by uwsgi* (I know it can be supported 
by Daphne too. But since the real-time part is not working I decide to use 
uwsgi): 
uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket=666 
--processes=6

*daphne*:
daphne mysite.asgi:channel_layer --port 8000 --bind 0.0.0.0 -v2 &
python manage.py runworker -v2 &

*nginx configuration:*
upstream websocket { server 0.0.0.0:8000; } server { listen 80; server_name 
mysite.com; charset utf-8; client_max_body_size 20M; location /static { 
alias /path/to/mysite/static; } location / { include 
/etc/nginx/uwsgi_params;
uwsgi_pass unix:///path/to/mysite/mysite.sock; } location /ws { proxy_pass 
http://websocket; 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;
}
}

One thing that I don't understand is that if I try to use Daphne to support 
both real-time and non-real-time communication by deleting the uwsgi block 
"location / {}" and renaming "location /ws {}" to "location / {}" the nginx 
service cannot be restarted. Does it suggest any bug?

*first few lines in .js related to the discussion function:*
$(function() {
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws"; var 
chatsock = new ReconnectingWebSocket(ws_scheme + '://' + 
window.location.host + window.location.pathname);
..

-- 
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/784a9296-059c-4a74-b952-cc9e6c8db709%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 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? 

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 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 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 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 

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 

Re: How to Speed up Loading the First Page of Django Project?

2017-11-21 Thread flora . xiaoyun . huang
But that's all I revised of the code. The configuration file of server 
engine and all the other things keep the same.

On Tuesday, November 21, 2017 at 2:09:08 PM UTC-5, Jason wrote:
>
> That is not a good solution.  There's a reason why the default password 
> hashing algorithm is complex.
>
> And I find it hard to believe that a password hash is the culprit here.  
> Maybe a quarter second or so added to a response, but 10 seconds?  that's 
> definitely not the cause.
>

-- 
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/94d70393-b9a4-43d3-857c-acc9ba9134a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to Speed up Loading the First Page of Django Project?

2017-11-21 Thread flora . xiaoyun . huang
Hi Jason,

Thanks for your help! I just solved the bug. 

The reason of the bug is that in the first step after I verify the worker's 
identification, I should put them in the database. And in django default 
setting, PASSWORD_HASHERS is set to PBKDF2 to hash the password for each 
worker. It is a complex algorithm, slowing down the speed to put users in 
the database. So I change PASSWORD_HASHERS to SHA1P. In this way, the user 
is put in the database faster, thus the first page is loaded faster.

On Tuesday, November 21, 2017 at 9:15:54 AM UTC-5, Jason wrote:
>
> Does that worker call execute slowly each time you call it?  Or is it just 
> the once?
>
> I'd copy that URL and try calling it several times with an REST API client 
> like Postman.  Does the request execute that slowly each time you call it, 
> or is it just the initial call that is slow?
>

-- 
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/34e36052-9c46-4c07-8386-2e21c9633422%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to Speed up Loading the First Page of Django Project?

2017-11-19 Thread flora . xiaoyun . huang
Hi,

The worker id and hit id are passed via GET. (It's a website for amazon 
mechanical turker to finish tasks.) And views.py checked their worker id 
and hit id to see whether they are valid. If they're valid, then the turker 
will be directed to the following pages.

On Sunday, November 19, 2017 at 5:40:21 AM UTC-5, Antonis Christofides 
wrote:
>
> Hello,
>
> How does the verification work?
>
> Regards,
>
> Antonis
>
> Antonis Christofideshttp://djangodeployment.com
>
> On 2017-11-19 02:38, flora.xia...@gmail.com  wrote:
>
> Thank you for your reply. The first page always loads slowly while the 
> rest of the pages loads at a normal speed. Whether I restart the apache or 
> not doesn't affect the speed of loading the first page - always slow. 
>
> Below is the configuration file in the sites-available folder under 
> apache. My apache is 2.4.
> 
> ServerAdmin webmaster@localhost
>
> DocumentRoot /var/www/html
> 
> Options FollowSymLinks
> AllowOverride None
> 
> 
> Options Indexes FollowSymLinks MultiViews
> AllowOverride None
> Require all granted
> 
>
> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
> 
> AllowOverride None
> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
> Require all granted
> 
> ErrorLog /var/log/apache2/error.log
>
> # Possible values include: debug, info, notice, warn, error, crit,
> # alert, emerg.
> LogLevel warn
>
> CustomLog /var/log/apache2/access.log combined
>
> Alias /doc/ "/usr/share/doc/"
> 
> Options Indexes MultiViews FollowSymLinks
> AllowOverride None
> Require all granted
> Allow from 127.0.0.0/255.0.0.0 ::1/128
> 
>
> Alias /static path/to/my/project/static
> 
> Require all granted
> 
>
>   
> 
> Require all granted
> 
> 
>
>
>   WSGIDaemonProcess myproject 
> python-path=path/to/my/project:path/to/my/project/lib/python2.7/site-packages
>   WSGIProcessGroup myproject
>   WSGIScriptAlias / path/to/my/project/myproject/wsgi.py
> 
>
> Thank you!
>
> 在 2017年11月17日星期五 UTC-5上午8:27:24,Jason写道: 
>>
>> I would suggest you post the configuration file here as well as the 
>> server specifications and average CPU/memory usage.  Because what you're 
>> describing is definitely not normal and is most likely related to how 
>> Apache is configured.
>>
>> A point of clarification: does the first page always load slowly, or is 
>> it just the first page after you restart the server?
>>
>> -- 
> 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/4cb4d8a9-6709-4f89-923f-bf5cc311e05a%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/10f58d4b-fd3f-461f-81a3-f0f8d2a6554e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to Speed up Loading the First Page of Django Project?

2017-11-18 Thread flora . xiaoyun . huang
And this is the first few lines of requests in the network section in 
developer tools. You can see that the first step to verify the user's 
identification takes so long.




When multiple users pop in, the memory usage of the server will be very 
high.

在 2017年11月17日星期五 UTC-5上午8:27:24,Jason写道:
>
> I would suggest you post the configuration file here as well as the server 
> specifications and average CPU/memory usage.  Because what you're 
> describing is definitely not normal and is most likely related to how 
> Apache is configured.
>
> A point of clarification: does the first page always load slowly, or is it 
> just the first page after you restart the server?
>
>

-- 
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/eb812b22-e7c9-4317-8db2-4a7ecc2f6d1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to Speed up Loading the First Page of Django Project?

2017-11-18 Thread flora . xiaoyun . huang
Thank you for your reply. The first page always loads slowly while the rest 
of the pages loads at a normal speed. Whether I restart the apache or not 
doesn't affect the speed of loading the first page - always slow.

Below is the configuration file in the sites-available folder under apache. 
My apache is 2.4.

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

Options FollowSymLinks
AllowOverride None


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted


ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"

Options Indexes MultiViews FollowSymLinks
AllowOverride None
Require all granted
Allow from 127.0.0.0/255.0.0.0 ::1/128


Alias /static path/to/my/project/static

Require all granted


  

Require all granted




  WSGIDaemonProcess myproject 
python-path=path/to/my/project:path/to/my/project/lib/python2.7/site-packages
  WSGIProcessGroup myproject
  WSGIScriptAlias / path/to/my/project/myproject/wsgi.py


Thank you!

在 2017年11月17日星期五 UTC-5上午8:27:24,Jason写道:
>
> I would suggest you post the configuration file here as well as the server 
> specifications and average CPU/memory usage.  Because what you're 
> describing is definitely not normal and is most likely related to how 
> Apache is configured.
>
> A point of clarification: does the first page always load slowly, or is it 
> just the first page after you restart the server?
>
>

-- 
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/4cb4d8a9-6709-4f89-923f-bf5cc311e05a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to Speed up Loading the First Page of Django Project?

2017-11-16 Thread flora . xiaoyun . huang
Hi,

I am deploying a Django project on Apache2. The Apache is running using 
mod_wsgi daemon mode. The first page of the website usually loads so slow. 
Before loading the first page (html, css) the user's identification should 
be verified (check the variable they pass through GET). When checking the 
developer tools I find that it is the verification that takes 10 to 20 
seconds. The most of time is stuck in waiting (TTFB). An Apache process is 
created for each user. On the server, the very slow load corresponds with a 
100% CPU use.

I find similar question here (
https://stackoverflow.com/questions/1702562/speeding-up-the-first-page-load-in-django).
 
However, revising the configuration file is not helpful.

Is there anyone who has an idea of the problem? Or do I need to provide 
more information about the problem? Thanks.

-- 
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/93680fda-2b06-463c-84b5-f35de2039730%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.