question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Daphne not working in production

See original GitHub issue

Daphne not working properly in production

these are few files

#Procfile

web: gunicorn django_analytics.wsgi --log-file -
web: daphne django_analytics.asgi:channel_layer --port $PORT --bind 0.0.0.0 -v2

#settings.py

"""
Django settings for django_analytics project.

Generated by 'django-admin startproject' using Django 2.1.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(_file_)))


# print(STATICFILES_DIRS)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'zrqi^g%%r%ac-tppuzt1#58xtxr!7^xi=s-^$nyzc65+snyn!o'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["*"]


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'channels',
    'view_analytics',
    'analytics',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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',
    # 'analytics.middlewares.TimingMiddleware'

]

ROOT_URLCONF = 'django_analytics.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 = 'django_analytics.wsgi.application'
ASGI_APPLICATION = 'django_analytics.routings.application'


CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels.layers.InMemoryChannelLayer",
        "CONFIG": {
        },
    },
}
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

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.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_ROOT = "/app/view_analytics/static",
STATIC_URL = '/static/'



#asgi.py

import os
import django
from channels.layers import get_channel_layer
from channels.routing import get_default_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_analytics.settings")
django.setup()
channel_layer = get_channel_layer()
application = get_default_application()

This was the error log

2018-11-13T16:48:47.448224+00:00 app[web.1]: 2018-11-13 16:48:47,448 ERROR Traceback (most recent call last): 2018-11-13T16:48:47.448245+00:00 app[web.1]: File “/app/.heroku/python/lib/python3.6/site-packages/daphne/http_protocol.py”, line 160, in process 2018-11-13T16:48:47.448247+00:00 app[web.1]: “server”: self.server_addr, 2018-11-13T16:48:47.448249+00:00 app[web.1]: File “/app/.heroku/python/lib/python3.6/site-packages/twisted/internet/defer.py”, line 1416, in _inlineCallbacks 2018-11-13T16:48:47.448251+00:00 app[web.1]: result = result.throwExceptionIntoGenerator(g) 2018-11-13T16:48:47.448253+00:00 app[web.1]: File “/app/.heroku/python/lib/python3.6/site-packages/twisted/python/failure.py”, line 491, in throwExceptionIntoGenerator 2018-11-13T16:48:47.448254+00:00 app[web.1]: return g.throw(self.type, self.value, self.tb) 2018-11-13T16:48:47.448256+00:00 app[web.1]: File “/app/.heroku/python/lib/python3.6/site-packages/daphne/server.py”, line 186, in create_application 2018-11-13T16:48:47.448258+00:00 app[web.1]: application_instance = yield deferToThread(self.application, scope=scope) 2018-11-13T16:48:47.448259+00:00 app[web.1]: File “/app/.heroku/python/lib/python3.6/site-packages/twisted/python/threadpool.py”, line 250, in inContext 2018-11-13T16:48:47.448261+00:00 app[web.1]: result = inContext.theWork() 2018-11-13T16:48:47.448263+00:00 app[web.1]: File “/app/.heroku/python/lib/python3.6/site-packages/twisted/python/threadpool.py”, line 266, in <lambda> 2018-11-13T16:48:47.448264+00:00 app[web.1]: inContext.theWork = lambda: context.call(ctx, func, *args, **kw) 2018-11-13T16:48:47.448266+00:00 app[web.1]: File “/app/.heroku/python/lib/python3.6/site-packages/twisted/python/context.py”, line 122, in callWithContext 2018-11-13T16:48:47.448267+00:00 app[web.1]: return self.currentContext().callWithContext(ctx, func, *args, **kw) 2018-11-13T16:48:47.448269+00:00 app[web.1]: File “/app/.heroku/python/lib/python3.6/site-packages/twisted/python/context.py”, line 85, in callWithContext 2018-11-13T16:48:47.448270+00:00 app[web.1]: return func(args,*kw) 2018-11-13T16:48:47.448272+00:00 app[web.1]: TypeError: ‘InMemoryChannelLayer’ object is not callable

I am getting daphne internal server error 500

I also cant use redis 😦 what should I do

a similar error I found was https://github.com/django/channels/issues/1035

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
andrewgodwincommented, Nov 13, 2018

You don’t need a channel layer, unless you want to talk between different consumers. But if you need one, Redis is the only one we maintain.

2reactions
andrewgodwincommented, Nov 13, 2018

Hey, I’m afraid this issue tracker is for specific, reproduceable bugs, not general support requests - see https://channels.readthedocs.io/en/latest/support.html for where you should ask those.

In particular, you shouldn’t be setting an InMemoryChannelLayer for production usage, it’s for testing only.

Read more comments on GitHub >

github_iconTop Results From Across the Web

django - Daphne does not find *server* on production server
I am trying to use django-eventstream to implement SSE events. My code runs perfectly using manage.py runserver on the local PC.
Read more >
Running daphne in production - Mac OS X Server 10.11
The worker is running too via python manage.py runworker. My feeling is that I do not have Daphne configured properly to receive the...
Read more >
Deploying — Channels 4.0.0 documentation
To run Daphne, it just needs to be supplied with an application, much like a WSGI server would need to be. Make sure...
Read more >
ASGI errors when deploying Django project for production ...
but it does not work I tried a lot of ways and solutions, but it all fails. ... Daphne, Gunicorn, Uvicorn to run...
Read more >
Daphne causing Modulenotfound error on production - Async
Im trying to run daphne for websocket but its failing and throwing ... “path” was working previously on prod with re_path not so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found