skip to Main Content

I have a Django app I’m using Django channels when deploying this app to Heroku I get this error
‘RedisChannelLayer’ object is not callable

This is the trackback for this error

2020-08-29T19:33:37.543129+00:00 app[web.1]: 2020-08-29 19:33:37,542 DEBUG    HTTP b'GET' request for ['10.9.251.250', 35308]
2020-08-29T19:33:37.543586+00:00 app[web.1]: 2020-08-29 19:33:37,543 ERROR    Traceback (most recent call last):
2020-08-29T19:33:37.543592+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/daphne/http_protocol.py", line 180, in process
2020-08-29T19:33:37.543593+00:00 app[web.1]: "server": self.server_addr,
2020-08-29T19:33:37.543594+00:00 app[web.1]: TypeError: 'RedisChannelLayer' object is not callable
2020-08-29T19:33:37.543599+00:00 app[web.1]:
2020-08-29T19:33:37.543727+00:00 app[web.1]: 2020-08-29 19:33:37,543 DEBUG    HTTP 500 response started for ['10.9.251.250', 35308]
2020-08-29T19:33:37.544107+00:00 app[web.1]: 2020-08-29 19:33:37,543 DEBUG    HTTP close for ['10.9.251.250', 35308]
2020-08-29T19:33:37.544398+00:00 app[web.1]: 2020-08-29 19:33:37,544 INFO     "10.9.251.250" - - [03/Jan/1970:21:31:20 +0000] "GET /favicon.ico HTTP/1.1" 500 452 "https://belkahla-mohamed-chatapp.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.9 Safari/537.36"
2020-08-29T19:33:37.544593+00:00 app[web.1]: 2020-08-29 19:33:37,544 DEBUG    HTTP response complete for ['10.9.251.250', 35308]
2020-08-29T19:33:37.544687+00:00 app[web.1]: 10.9.251.250:35308 - - [29/Aug/2020:19:33:37] "GET /favicon.ico" 500 452

this is my asgi.py file:

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

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ProfilesApp.settings.development')
django.setup()
application = get_default_application()
channel_layer = get_channel_layer()

settings.py

ASGI_APPLICATION = "ProfilesApp.routing.application"
WSGI_APPLICATION = 'ProfilesApp.wsgi.application'
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
        },
    },
}

Please let me know how to fix that, thanks in advance

2

Answers


  1. Chosen as BEST ANSWER

    asgi.py should be like this :

    import os
    import django
    from channels.routing import get_default_application
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
    django.setup()
    application = get_default_application()
    

    and ProcFile should be like this

    web: daphne myproject.asgi:application --port $PORT --bind 0.0.0.0 -v2
    chatworker: python manage.py runworker --settings=myproject.settings.production -v2
    

  2. You are using wrong asgi configuration which was intended for channels 1.x

    as documentation states should look like

    """
    ASGI entrypoint. Configures Django and then runs the application
    defined in the ASGI_APPLICATION setting.
    """
    
    import os
    import django
    from channels.routing import get_default_application
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
    django.setup()
    application = get_default_application()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search