Web Socket don't make connection with Wss /https Django

34 views Asked by At

This is my asgi.py.

import os, django

from django.core.asgi import get_asgi_application
from channels.routing import get_default_application
django_asgi_app = get_asgi_application()
# from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter

from channels.auth import AuthMiddlewareStack
from django.urls import path 
from scraptaxiapp.consumers import UploadFileConsumer
from scraptaxiapp.routing import websocket_urlpatterns

print("websockets", websocket_urlpatterns, URLRouter(websocket_urlpatterns))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ScrapTaxi.settings")
django.setup()
application = ProtocolTypeRouter({
  'https': django_asgi_app,
  'websocket': AuthMiddlewareStack(URLRouter(websocket_urlpatterns))
})

This is my routing.py

from django.urls import re_path

from .consumers import UploadFileConsumer

websocket_urlpatterns = [
    re_path(r"^ws/UploadFile/$", UploadFileConsumer.as_asgi()),
    re_path("hello/", UploadFileConsumer.as_asgi())
]

This is my settings

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels.layers.InMemoryChannelLayer",
    },
}

i have started daphne as daphne -e ssl:8001:privateKey=private_key.pem:certKey=certificate.pem ScrapTaxi.asgi:application -p 8001 -b x.x.x.x

my ssl is self signed. now after this i am able to connect web socket with ws but not with wss C:\Users\PC>wscat -c "wss://x.x.x.x:8001/ws/UploadFile/" --no-check error: Client network socket disconnected before secure TLS connection was established

Now i am using runserverplus for django application so i have to use wss for channel connection.

0

There are 0 answers