“redischannellayer”对象不可调用

6mzjoqzu  于 2021-06-08  发布在  Redis
关注(0)|答案(2)|浏览(373)

我有一个django应用程序,我正在使用django频道,当我将这个应用程序部署到heroku时,我发现这个错误“redischannellayer”对象是不可调用的
这是此错误的回溯

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

这是我的asgi.py文件:

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()

设置.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')],
        },
    },
}

请让我知道如何修复,提前谢谢

djmepvbi

djmepvbi1#

asgi.py应该是这样的:

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()

procfile应该是这样的

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

wlzqhblo2#

您使用了错误的asgi配置,该配置原本用于通道1.x
文件状态应该是这样的

"""
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()

相关问题