소개
게시글
질문&답변
run_test_hello_channel.py 오류
코드 받아서 돌려봤는데 잘 돌아가네요..어디선가 코드를 잘못 썻나봐요 감사합니다!
- 0
- 4
- 511
질문&답변
run_test_hello_channel.py 오류
#!/usr/bin/env python """Django's command-line utility for administrative tasks.""" import os import sys def main(): """Run administrative tasks.""" os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv) if __name__ == '__main__': main()manage.py에 경로설정돼있습니다.layers값은 정상적으로 출력됩니다. ~/Documents/GitHub/Quickie test-chat !3 > python3 run_test_hello_channel.py 4s py Quickie 13:59:04 {‘default’: {‘BACKEND’: ‘channels_redis.core.RedisChannelLayer’, ‘CONfIG’: {‘hosts’: [{‘host’: ‘redis-11279.c54.ap-northeast-1-2.ec2.cloud.redislabs.com’, ‘port’: 11279, ‘password’: ‘lRiJKj6xSMpubVvQ2QLNeft05INxmItmv’}]}}} RedisChannelLayer(hosts=[{‘address’: ‘redis://localhost:6379’}]) Traceback (most recent call last): File “/Users/kang-yongmin/Documents/GitHub/Quickie/venv/lib/python3.10/site-packages/redis/asyncio/connection.py”, line 567, in connect await self.retry.call_with_retry( File “/Users/kang-yongmin/Documents/GitHub/Quickie/venv/lib/python3.10/site-packages/redis/asyncio/retry.py”, line 59, in call_with_retry return await do() File “/Users/kang-yongmin/Documents/GitHub/Quickie/venv/lib/python3.10/site-packages/redis/asyncio/connection.py”, line 604, in _connect reader, writer = await asyncio.open_connection( File “/Users/kang-yongmin/.pyenv/versions/3.10.4/lib/python3.10/asyncio/streams.py”, line 47, in open_connection transport, _ = await loop.create_connection( File “/Users/kang-yongmin/.pyenv/versions/3.10.4/lib/python3.10/asyncio/base_events.py”, line 1072, in create_connection raise OSError(‘Multiple exceptions: {}‘.format( OSError: Multiple exceptions: [Errno 61] Connect call failed (‘::1’, 6379, 0, 0), [Errno 61] Connect call failed (‘127.0.0.1’, 6379) During handling of the above exception, another exception occurred: Traceback (most recent call last): File “/Users/kang-yongmin/Documents/GitHub/Quickie/run_test_hello_channel.py”, line 25, in asyncio.run(main()) File “/Users/kang-yongmin/.pyenv/versions/3.10.4/lib/python3.10/asyncio/runners.py”, line 44, in run return loop.run_until_complete(main) File “/Users/kang-yongmin/.pyenv/versions/3.10.4/lib/python3.10/asyncio/base_events.py”, line 646, in run_until_complete return future.result() File “/Users/kang-yongmin/Documents/GitHub/Quickie/run_test_hello_channel.py”, line 19, in main await channel_layer.send(‘hello’, message_dict) File “/Users/kang-yongmin/Documents/GitHub/Quickie/venv/lib/python3.10/site-packages/channels_redis/core.py”, line 218, in send await connection.zremrangebyscore( File “/Users/kang-yongmin/Documents/GitHub/Quickie/venv/lib/python3.10/site-packages/redis/asyncio/client.py”, line 502, in execute_command conn = self.connection or await pool.get_connection(command_name, **options) File “/Users/kang-yongmin/Documents/GitHub/Quickie/venv/lib/python3.10/site-packages/redis/asyncio/connection.py”, line 1363, in get_connection await connection.connect() File “/Users/kang-yongmin/Documents/GitHub/Quickie/venv/lib/python3.10/site-packages/redis/asyncio/connection.py”, line 575, in connect raise ConnectionError(self._error_message(e)) redis.exceptions.ConnectionError: Error connecting to localhost:6379. Multiple exceptions: [Errno 61] Connect call failed (‘::1’, 6379, 0, 0), [Errno 61] Connect call failed (‘127.0.0.1’, 6379).
- 0
- 4
- 511
질문&답변
run_test_hello_channel.py 오류
redislabs의 서버를 사용하려하고 있습니다.settings.py""" Django settings for mysite project. Generated by 'django-admin startproject' using Django 4.1.5. For more information on this file, see https://docs.djangoproject.com/en/4.1/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.1/ref/settings/ """ from pathlib import Path from environ import Env # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent env = Env() env_path = BASE_DIR / ".env" if env_path.exists(): with env_path.open(encoding="utf8") as f: env.read_env(f, overwrite=True) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-zlx#3$sp$wca%lnq2k4)6@lz+8aak(n!buko-%(o8=__!ht=5o' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'channels', 'daphne', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app', ] 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', ] ROOT_URLCONF = 'mysite.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 = 'mysite.wsgi.application' ASGI_APPLICATION = 'mysite.asgi.application' # Database # https://docs.djangoproject.com/en/4.1/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } } #django channels layer if "CHANNEL_LAYER_REDIS_URL" in env: channel_layer_redis = env.db_url("CHANNEL_LAYER_REDIS_URL") CHANNEL_LAYERS = { "default" : { "BACKEND": "channels_redis.core.RedisChannelLayer", "CONfIG": { "hosts": [ { "host": channel_layer_redis["HOST"], "port": channel_layer_redis.get("PORT") or 6379, "password": channel_layer_redis["PASSWORD"], } ] } } } # Password validation # https://docs.djangoproject.com/en/4.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/4.1/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.1/howto/static-files/ STATIC_URL = 'static/' # Default primary key field type # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' .envCHANNEL_LAYER_REDIS_URL=redis://:lRiJKj6xSMpubVvQ2QLNft05INxmItmv@redis-11279.c54.ap-northeast-1-2.ec2.cloud.redislabs.com:11279 쉘에서는 다음과 같이 잘 작동하고 있습니다.~/Documents/GitHub/Quickie test-chat !3 > python3 manage.py shell 37s py Quickie 13:41:59 Python 3.10.4 (main, Jan 3 2023, 21:09:20) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin Type “help”, “copyright”, “credits” or “license” for more information. (InteractiveConsole) >>> from django.conf import settings >>> print(settings.CHANNEL_LAYERS) {‘default’: {‘BACKEND’: ‘channels_redis.core.RedisChannelLayer’, ‘CONfIG’: {‘hosts’: [{‘host’: ‘redis-11279.c54.ap-northeast-1-2.ec2.cloud.redislabs.com’, ‘port’: 11279, ‘password’: ‘lRiJKj6xSMpubVvQ2QLNft05INxmItmv’}]}}} >>> exit()
- 0
- 4
- 511