Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Google云平台上部署Django Channel应用程序_Django_Google App Engine_Websocket_Django Channels_Asgi - Fatal编程技术网

在Google云平台上部署Django Channel应用程序

在Google云平台上部署Django Channel应用程序,django,google-app-engine,websocket,django-channels,asgi,Django,Google App Engine,Websocket,Django Channels,Asgi,我正在开发我的第一个django channel应用程序,我想在谷歌云平台上部署我的django channel应用程序,它在本地服务器上运行良好,但当我在谷歌云平台上部署它时,它会给我错误: WebSocket连接到'wss://sockets-263709.appspot.com/ws/chat/user2/'失败:WebSocket握手期间出错:意外响应代码:400 我已经研究过了,但不知道如何设置,以下是我的代码: 入口点: from Frames.wsgi import applica

我正在开发我的第一个django channel应用程序,我想在谷歌云平台上部署我的django channel应用程序,它在本地服务器上运行良好,但当我在谷歌云平台上部署它时,它会给我错误:

WebSocket连接到'wss://sockets-263709.appspot.com/ws/chat/user2/'失败:WebSocket握手期间出错:意外响应代码:400

我已经研究过了,但不知道如何设置,以下是我的代码:

入口点

from Frames.wsgi import application
app = application
import os

from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Frames.settings')
application = get_wsgi_application()
WSGI_APPLICATION = 'Frames.wsgi.application'
ASGI_APPLICATION = "Frames.routing.application"

CHANNEL_LAYERS={
    "default":{
      "BACKEND": "channels_redis.core.RedisChannelLayer",
      "CONFIG": {
                "hosts": [("sockets-263709.appspot.com", 6379)],
            },
    },
}

var wsStart='ws://';
    // check if it is secured then assign wss://
    if (loc.protocol==='https:'){
        wsStart="wss://"
    }

    var chatSocket = new WebSocket(wsStart +window.location.host +
        '/ws/chat/' + roomName + '/');
wsgi.py

from Frames.wsgi import application
app = application
import os

from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Frames.settings')
application = get_wsgi_application()
WSGI_APPLICATION = 'Frames.wsgi.application'
ASGI_APPLICATION = "Frames.routing.application"

CHANNEL_LAYERS={
    "default":{
      "BACKEND": "channels_redis.core.RedisChannelLayer",
      "CONFIG": {
                "hosts": [("sockets-263709.appspot.com", 6379)],
            },
    },
}

var wsStart='ws://';
    // check if it is secured then assign wss://
    if (loc.protocol==='https:'){
        wsStart="wss://"
    }

    var chatSocket = new WebSocket(wsStart +window.location.host +
        '/ws/chat/' + roomName + '/');
Asgi.py

import os
import django
from channels.routing import get_default_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Frames.settings')
django.setup()
application = get_default_application()
设置.py

from Frames.wsgi import application
app = application
import os

from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Frames.settings')
application = get_wsgi_application()
WSGI_APPLICATION = 'Frames.wsgi.application'
ASGI_APPLICATION = "Frames.routing.application"

CHANNEL_LAYERS={
    "default":{
      "BACKEND": "channels_redis.core.RedisChannelLayer",
      "CONFIG": {
                "hosts": [("sockets-263709.appspot.com", 6379)],
            },
    },
}

var wsStart='ws://';
    // check if it is secured then assign wss://
    if (loc.protocol==='https:'){
        wsStart="wss://"
    }

    var chatSocket = new WebSocket(wsStart +window.location.host +
        '/ws/chat/' + roomName + '/');
客户端

from Frames.wsgi import application
app = application
import os

from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Frames.settings')
application = get_wsgi_application()
WSGI_APPLICATION = 'Frames.wsgi.application'
ASGI_APPLICATION = "Frames.routing.application"

CHANNEL_LAYERS={
    "default":{
      "BACKEND": "channels_redis.core.RedisChannelLayer",
      "CONFIG": {
                "hosts": [("sockets-263709.appspot.com", 6379)],
            },
    },
}

var wsStart='ws://';
    // check if it is secured then assign wss://
    if (loc.protocol==='https:'){
        wsStart="wss://"
    }

    var chatSocket = new WebSocket(wsStart +window.location.host +
        '/ws/chat/' + roomName + '/');
Requirements.txt

absl-py==0.8.1
aioredis==1.3.1
asgiref==3.2.3
astor==0.8.1
async-timeout==3.0.1
attrs==19.3.0
autobahn==19.11.1
Automat==0.8.0
certifi==2019.11.28
cffi==1.13.2
channels==2.3.1
channels-redis==2.4.1
chardet==3.0.4
constantly==15.1.0
daphne==2.4.0
Django==3.0.1
djangochannelsrestframework==0.0.3
djangorestframework==3.11.0
gast==0.3.2
google-pasta==0.1.8
grpcio==1.25.0
h5py==2.10.0
hiredis==1.0.1
hyperlink==19.0.0
idna==2.8
incremental==17.5.0
Markdown==3.1.1
msgpack==0.6.2
mysqlclient==1.4.6
protobuf==3.11.1
pyasn1==0.4.8
pyasn1-modules==0.2.7
pycparser==2.19
PyHamcrest==1.9.0
PyMySQL==0.9.3
pyOpenSSL==19.1.0
pytz==2019.3
PyYAML==5.2
requests==2.22.0
scipy==1.3.3
service-identity==18.1.0
six==1.13.0
sqlparse==0.3.0
termcolor==1.1.0
tqdm==4.40.2
Twisted==19.10.0
txaio==18.8.1
urllib3==1.25.7
我从WSGI.py开始,我已经研究并了解了daphne,但不知道,有谁能告诉我如何正确部署它。连接在本地成功打开。
设置中的配置(CHANNEL_LAYERS)中是否正确提到了主机。py

您能告诉我您在哪里上传这个Django应用程序吗?您是在使用Google App Engine,还是在使用GCE(Google Compute Instance)实例为其提供服务?我正在Google App Engine中上载您可以按照此操作创建与WebSocket的持久连接。如果对你有帮助,请告诉我。