none
Problem with connecting to websockets on django App on Azure RRS feed

  • Question

  • I've created a django app that works locally fine. After deploying it on Azure via VS Code, html pages are working fine but seems that I have a problem connecting to the websocket, even though that I enabled the websocket on my azure portal app.

    Console log: Firefox can’t establish a connection to the server at wss://myapp.azurewebsites.net:8080

    The app is runing on docker:

    FROM python:3.7-buster
    
    # Define environment variables
    ENV ACCEPT_EULA=Y
    ENV PYTHONUNBUFFERED=1
    
    # Expose port
    EXPOSE 8080/tcp
    
    # Create app directory
    WORKDIR /django_ui
    
    # Copy all files to image
    COPY . .
    
    # Install recuired apt packages
    RUN apt-get update && apt-get install -y --no-install-recommends gcc unixodbc unixodbc-dev build-essential curl
    
    # Install microsoft sql driver for debian
    RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
       curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
       apt-get update && \
       apt-get install -qq -y msodbcsql17 && \
       apt-get install -qq -y mssql-tools && \
       echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile && \
       echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
    
    # Install recuired pip packages
    RUN pip install -r ./req/requirements.txt
    
    # Remove requirements
    RUN rm -rf ./req
    
    # Run django websocket server 0 0 0 0
    CMD ["python3", "manage.py", "runserver", "0.0.0.0:8080"] 

    The endpoint in my .js file looks like this:

    // Get endpoint
    var loc = window.location;
    var wsStart = 'wss://';
    var port=":8080"
    var endpoint = wsStart + loc.host + port;
    
    // Create new client socket
    var socket = new WebSocket(endpoint); 

    Here is the code in my settings.py: 

    INSTALLED_APPS = [
        "channels",
        "home",
        "django.contrib.admin",
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "django.contrib.sessions",
        "django.contrib.messages",
        "django.contrib.staticfiles",
    ]
    
    MIDDLEWARE = [
        "django.middleware.security.SecurityMiddleware",
        "whitenoise.middleware.WhiteNoiseMiddleware",
        "django.contrib.sessions.middleware.SessionMiddleware",
        "django.middleware.common.CommonMiddleware",
        "django.middleware.csrf.CsrfViewMiddleware",
        "django.contrib.auth.middleware.AuthenticationMiddleware",
        "django.contrib.messages.middleware.MessageMiddleware",
        "django.middleware.clickjacking.XFrameOptionsMiddleware",
    ]
    
    ROOT_URLCONF = "ulv.urls"
    
    TEMPLATES = [
        {
            "BACKEND": "django.template.backends.django.DjangoTemplates",
            "DIRS": [],
            "APP_DIRS": True,
            "OPTIONS": {
                "context_processors": [
                    "django.template.context_processors.debug",
                    "django.template.context_processors.request",
                    "django.contrib.auth.context_processors.auth",
                    "django.contrib.messages.context_processors.messages",
                ],
            },
        },
    ]
    
    WSGI_APPLICATION = "ulv.wsgi.application"
    
    AUTH_PASSWORD_VALIDATORS = [
        {
            "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
        },
        {
            "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
        },
        {
            "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
        },
        {
            "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
        },
    ]
    
    
    # Internationalization
    # https://docs.djangoproject.com/en/2.2/topics/i18n/
    
    LANGUAGE_CODE = "en-us"
    
    TIME_ZONE = "UTC"
    
    USE_I18N = True
    
    USE_L10N = True
    
    USE_TZ = True
    
    
    # Static files (CSS, JavaScript, Images)
    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
    STATIC_URL = '/static/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    
    
    
    # Channels
    ASGI_APPLICATION = "ulv.routing.application"
    
    
    

    Does any one has an idea how to fix this?


    Monday, June 22, 2020 7:41 AM