Django频道-客户端有时不接收消息,直到根本没有收到消息为止 [英] Django channels - Client receives message sometimes and not other times till it doesn't recieve it at all

查看:159
本文介绍了Django频道-客户端有时不接收消息,直到根本没有收到消息为止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新

我认为问题出在python版本。在我的本地主机上,当我安装python 3.6时,它工作正常。在生产中,该问题首先出现在我的位置,我有3.8。将本地python版本更改为3.8之后,我可以看到与生产环境相同的问题。

I think the issue is with python version. On my localhost it worked fine when I had python 3.6. On production, where the issue appeared first, I have 3.8. After I changed my localhost python version to 3.8 I could see the same issue as was on the production.

原始帖子

我在使用Daphne + Nginx设置django-channel时遇到问题。

I am facing an issue with setting up django-channels with Daphne + Nginx.

当我重新启动服务器并在浏览器中打开页面时,客户端会获得(项目)列表从websocket。当我刷新页面时,列表不会加载。然后在另一个刷新中加载。再次刷新时,它不会加载,依此类推。最后,即使经过多次刷新,它也不会加载。但是,如果我再次重新启动服务器并在浏览器中重新加载页面,列表将像以前一样加载,并且在下一次刷新时不会加载,依此类推。

When I reboot the server and open the page in the browser the client gets the list(of items) from websocket. When I refresh the page the list doesn't load. Then on another refresh it loads. On another refresh it doesn't load and so on. Finally it doesn't load at even after many refreshes. But if I reboot the server again and reload the page in the browser the list loads as before and on next refresh it doesn't and so on.

在寻找时,websocket似乎总是可以连接的在开发人员工具中。

The websocket always seems to connect when looking at the developer tool.

我尝试在Google和SO上进行深入研究,但似乎并没有弄清问题的原因。

I have tried digging into it on google and SO but doesn't seem to get to the cause of the problem.

这是我的Nginx配置文件:

here is my nginx configuration file:

upstream backserver {
 server localhost:8000;
}


server {
 server_name MY_IP mydomain.com www.mydomain.com;

root /home/muser/myproject;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
     alias /home/myuser/myproject/static/;

}


    if (-f $document_root/maintenance_ON.txt) {
         return 503;
    }
    error_page 503 @maintenance;

    location @maintenance {
    rewrite ^(.*)$ /site_maintenance.html break;
 }

location / {

    proxy_pass http://backserver;
    proxy_http_version  1.1;
    proxy_set_header    Upgrade $http_upgrade;
    proxy_set_header    Connection "Upgrade";
    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;

}

listen [::]:443 ipv6only=on ssl; ##added by me(developer)
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
  if ($host = www.mydomain.com) {
    return 301 https://$host$request_uri;
 } # managed by Certbot


 if ($host = mydomain.com) {
    return 301 https://$host$request_uri;
 } # managed by Certbot

 listen 80;
 listen [::]:80 ipv6only=on;
 server_name MY_IP mydomain.com www.mydomain.com;
 return 404; # managed by Certbot

}

此外,我在日志中也收到此错误。我认为它仅在重新启动时出现。

Also, I get this error in the log. I think it only appears at reboot.

ERROR    Exception in callback AsyncioSelectorReactor.callLater.<locals>.run() at /home/myuser/path_to_virtual_env/lib/python3.8/site-packages/twisted/internet/asyncioreactor.py:287
handle: <TimerHandle when=121.470065138 AsyncioSelectorReactor.callLater.<locals>.run() at /home/myuser/path_to_virtual_env/lib/python3.8/site-packages/twisted/internet/asyncioreactor.py:287>
Traceback (most recent call last):
  File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "/home/myuser/path_to_virtual_env/lib/python3.8/site-packages/twisted/internet/asyncioreactor.py", line 290, in run
    f(*args, **kwargs)
  File "/home/myuser/path_to_virtual_env/lib/python3.8/site-packages/daphne/server.py", line 275, in application_checker
    exception = application_instance.exception()
asyncio.exceptions.CancelledError

请帮忙我整天和晚上都在

Please help I have spend whole day and evening on this.

谢谢

推荐答案

看来问题出在Python版本。这个问题出现时,我正在使用Python3.8。将Python版本更改为3.6之后,该问题似乎已解决。我没有尝试3.7版。

It seems the issue was due to Python version. I was using Python3.8 when this issue appeared. After changing Python version to 3.6 the issue seems fixed. I did not try version 3.7.

这篇关于Django频道-客户端有时不接收消息,直到根本没有收到消息为止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆