jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
895 stars 222 forks source link

django-websocker error: ValueError: message object is not of type RedisMessage #242

Open sam-thecoder opened 7 years ago

sam-thecoder commented 7 years ago

I'm learning how to setup django-websocket with redis https://django-websocket-redis.readthedocs.io/en/latest/api.html#use-redispublisher-from-inside-django-views and I'm calling it like this

message =  "Percentage {0}% \t {1}/{2} \t {3}".format(percentage, counter, (width * height), delta)
print message
socket = RenderView()
socket.get(request, message)

in the view

from django.views.generic.base import View
from ws4redis.publisher import RedisPublisher

class RenderView(View):
    facility = 'render-view'
    audience = {'broadcast': True}

    def __init__(self, *args, **kwargs):
        super(RenderView, self).__init__(*args, **kwargs)
        self.redis_publisher = RedisPublisher(facility=self.facility, **self.audience)

    def get(self, request, message):
        self.redis_publisher.publish_message(message)

I'm getting this error

    socket.get(request, message)
  File "/home/samuel/Documents/code/revamp/gallery/socket.py", line 13, in get
    self.redis_publisher.publish_message(message)
  File "/usr/local/lib/python2.7/dist-packages/ws4redis/redis_store.py", line 110, in publish_message
    raise ValueError('message object is not of type RedisMessage')
ValueError: message object is not of type RedisMessage
erikreed commented 7 years ago

You just need to wrap your message in RedisMessage.

E.g.

message = RedisMessage('data')