简体   繁体   中英

How to solve the error: 'tuple' object has no attribute 'decode' with django-channels

When I tried to execute the channels' tutorial in order to establishing the django website with websocket, the error message emerged:

AttributeError: 'tuple' object has no attribute 'decode'

I just executed following code:

$ python3 manage.py shell
>>> import channels.layers
>>> channel_layer = channels.layers.get_channel_layer()
>>> from asgiref.sync import async_to_sync
>>> async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'})

Tutorial link: https://channels.readthedocs.io/en/stable/tutorial/part_2.html

Environment: Ubuntu 20.04LTS with Python 3.8.10 django 4.1.3 channels 4.0.0 channels-redis 4.0.0 daphne 4.0.0 asgiref 3.5.2

I think the problem may caused by asgiref, but there is no documentation for reference.

I had the same bug, and because I encountered this issue I downgraded to channels_redis v 3.4.0 and the bug went away. Waiting for a nicer solution, I hope it will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM