I'm new to channels and trying to take another look after the jump to version 2. I'm running Windows 10 with PyCharm as my IDE using Django 1.11.8, Channels 2.0.2, asgiref 2.2.0, channels-redis 2.1.0
I'm working through the tutorial that is in PR https://github.com/django/channels/pull/954 and end up getting this message. I'm willing to bet this is some kind of problem with my setup but I don't know enough about channels at this point to be sure. The code I'm running is the state of the tutorial at the end of part 2.
[2018/03/11 19:49:11] HTTP GET /starborne/stuff/ 200 [0.02, 127.0.0.1:53046]
[2018/03/11 19:49:11] WebSocket HANDSHAKING /ws/chat/stuff/ [127.0.0.1:53088]
2018-03-11 19:49:11,978 - ERROR - server - Exception inside application:
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\channels\consumer.py", line 54, in __call__
await await_many_dispatch([receive, self.channel_receive], self.dispatch)
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\channels\utils.py", line 48, in await_many_dispatch
await dispatch(result)
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\asgiref\sync.py", line 110, in __call__
return await asyncio.wait_for(future, timeout=None)
File "C:\Users\jzmiller1\AppData\Local\Programs\Python\Python36-32\lib\asyncio\tasks.py", line 339, in wait_for
return (yield from fut)
File "C:\Users\jzmiller1\AppData\Local\Programs\Python\Python36-32\lib\concurrent\futures\thread.py", line 55, in run
result = self.fn(self.args, self.kwargs)
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\channels\db.py", line 13, in thread_handler
return super().thread_handler(loop, *args, *kwargs)
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\asgiref\sync.py", line 125, in thread_handler
return self.func(args, *kwargs)
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\channels\consumer.py", line 99, in dispatch
handler(message)
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\channels\generic\websocket.py", line 19, in websocket_connect
self.connect()
File "C:\Users\jzmiller1\PyCharmProjects\apparatchiki\starborne\consumers.py", line 14, in connect
self.channel_name
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\asgiref\sync.py", line 64, in __call__
return call_result.result()
File "C:\Users\jzmiller1\AppData\Local\Programs\Python\Python36-32\lib\concurrent\futures_base.py", line 405, in result
return self.__get_result()
File "C:\Users\jzmiller1\AppData\Local\Programs\Python\Python36-32\lib\concurrent\futures_base.py", line 357, in __get_result
raise self._exception
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\asgiref\sync.py", line 78, in main_wrap
result = await self.awaitable(args, *kwargs)
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\channels_redis\core.py", line 283, in group_add
async with self.connection(self.consistent_hash(group)) as connection:
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\channels_redis\core.py", line 403, in __aenter__
self.conn = await aioredis.create_redis(self.kwargs)
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\aioredis\commands__init__.py", line 177, in create_redis
loop=loop)
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\aioredis\connection.py", line 117, in create_connection
timeout, loop=loop)
File "C:\Users\jzmiller1\AppData\Local\Programs\Python\Python36-32\lib\asyncio\tasks.py", line 339, in wait_for
return (yield from fut)
File "C:\Users\jzmiller1\PyCharmProjects\virtualenvs\apparatchiki\lib\site-packages\aioredis\stream.py", line 33, in open_unix_connection
lambda: protocol, address, **kwds)
File "C:\Users\jzmiller1\AppData\Local\Programs\Python\Python36-32\lib\asyncioevents.py", line 351, in create_unix_connection
raise NotImplementedError
[2018/03/11 19:49:11] WebSocket DISCONNECT /ws/chat/stuff/ [127.0.0.1:53088]
You're apparently trying to create a UNIX socket under Windows, which is never going to work. Can you paste the value you have set for CHANNEL_LAYERS in your settings file?
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer", # use redis backend
"CONFIG": {
"hosts": [env('REDIS_URL'),], # set redis address
},
},
}
Alright, and what is the REDIS_URL environment variable set to when you run?
Seems the problem was in the form of the redis URL. I didn't include redis:// on the front of my redislabs URL. Once I made that change everything was fine. Sorry for issuing you on something so basic. The error message threw me off.
REDIS_URL=redis://[email protected]:port
No problem - that's an unfortunate side-effect of the url design, I guess. Hopefully someone else will find this useful when they run into the same problem later!
I'm new to channel and getting some similar error :
Exception in thread django-main-thread:
Traceback (most recent call last):
File "c:\users\win10\appdata\local\programs\python\python38-32\Lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "c:\users\win10\appdata\local\programs\python\python38-32\Lib\threading.py", line 870, in run
self._target(self._args, *self._kwargs)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(args, *kwargs)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\core\management__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(args, *kwargs)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\apps\config.py", line 116, in create
mod = import_module(mod_path)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\importlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\channels\apps.py", line 6, in
import daphne.server
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\daphne\server.py", line 20, in
asyncioreactor.install(twisted_loop)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\twisted\internet\asyncioreactor.py", line 320, in install
reactor = AsyncioSelectorReactor(eventloop)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\twisted\internet\asyncioreactor.py", line 69, in __init__
super().__init__()
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\twisted\internet\base.py", line 571, in __init__
self.installWaker()
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\twisted\internet\posixbase.py", line 286, in installWaker
self.addReader(self.waker)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\twisted\internet\asyncioreactor.py", line 151, in addReader
self._asyncioEventloop.add_reader(fd, callWithLogger, reader,
File "c:\users\win10\appdata\local\programs\python\python38-32\Lib\asyncioevents.py", line 501, in add_reader
raise NotImplementedError
NotImplementedError
I'm unable to locate CHANNEL_LAYERS variable at my settings.py.
Any idea what to do?
I'm new to channel and getting some similar error :
Exception in thread django-main-thread:
Traceback (most recent call last):
File "c:\users\win10\appdata\local\programs\python\python38-32\Lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "c:\users\win10\appdata\local\programs\python\python38-32\Lib\threading.py", line 870, in run
self._target(self._args, self._kwargs)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(args, *kwargs)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\core\management__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(args, *kwargs)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\django\apps\config.py", line 116, in create
mod = import_module(mod_path)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\importlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\channels\apps.py", line 6, in
import daphne.server
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\daphne\server.py", line 20, in
asyncioreactor.install(twisted_loop)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\twisted\internet\asyncioreactor.py", line 320, in install
reactor = AsyncioSelectorReactor(eventloop)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\twisted\internet\asyncioreactor.py", line 69, in *init
super().init()
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\twisted\internet\base.py", line 571, in init
self.installWaker()
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\twisted\internet\posixbase.py", line 286, in installWaker
self.addReader(self.waker)
File "C:\Users\win10\PycharmProjects\chatting\env\lib\site-packages\twisted\internet\asyncioreactor.py", line 151, in addReader
self._asyncioEventloop.add_reader(fd, callWithLogger, reader,
File "c:\users\win10\appdata\local\programs\python\python38-32\Lib\asyncioevents.py", line 501, in add_reader
raise NotImplementedError
NotImplementedErrorI'm unable to locate CHANNEL_LAYERS variable at my settings.py.
Any idea what to do?
Here is the solution.
https://stackoverflow.com/questions/58908293/i-keep-getting-notimplementederror-error-when-starting-django-server
I've sovled with that.
No need to modify the twisted package for this.
Just add this somewhere (e.g. your django's project __init__.py file):
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
There's surely going to be better places than the __init__.py file, but can't say it's a good place either.
I'm a bit worried that I'm "fixing" this, but per what @andrewgodwin says, it's probably just happening because something else is not set correctly :/
thanks @andrewgodwin your given solution is working
Most helpful comment
No need to modify the twisted package for this.
Just add this somewhere (e.g. your django's project
__init__.pyfile):There's surely going to be better places than the
__init__.pyfile, but can't say it's a good place either.I'm a bit worried that I'm "fixing" this, but per what @andrewgodwin says, it's probably just happening because something else is not set correctly :/