django-websocket-redis icon indicating copy to clipboard operation
django-websocket-redis copied to clipboard

basestring is not defined

Open nikksbagul opened this issue 9 years ago • 5 comments

I am using python 3.4, django 1.9 and I got 'basestring is not defined' error. So I replaced basestring word with str into '_get_message_channels' method of 'redis store' class in 'redis store' file, now it's working fine. Please make appropiate changes into these package.

Thank You.

nikksbagul avatar Apr 09 '16 13:04 nikksbagul

I also got same issue and I replaced 'basestring' with 'str' to solve problem.

Dharmik8478 avatar Apr 15 '16 12:04 Dharmik8478

A coworker had the same issue on Python 3.4 and Django 1.9. Looks like setting users or groups to a string is deprecated. You should be passing in a list or tuple of user or group names.

if isinstance(groups, (list, tuple)):
    # message is delivered to all listed groups
    . . .
elif isinstance(groups, basestring):
    # message is delivered to the named group
    warnings.warn('Wrap a single group into a list or tuple', DeprecationWarning)
    channels.append('{prefix}group:{0}:{facility}'.format(groups, prefix=prefix, facility=facility))

redis_store.py:128

ticalcster avatar Sep 12 '16 19:09 ticalcster

There is also an issue when passing in a lazy object (like a queryset) or a generator (as it's not a list of tuple).

I'll try to upload a fix in the next few days

nanuxbe avatar Jun 06 '18 08:06 nanuxbe

Got the same issue, basestring is not found and I'm using the Python 3.7 and Django 3.0. Now I'm sending the users as a list or tuple to avoid this issue now. it would be great, if we can use the six module to make this compatible since we are in early stage of python 2 to 3 transition or use the proper exceptional handling.

from six import string_types elif isinstance(users, string_types):

or

try:
    basestring
except:
    basestring = str

venkatpython avatar Feb 11 '21 14:02 venkatpython

I know, I should remove the Python-2 compatibility layer 🤔

jrief avatar Feb 12 '21 21:02 jrief