Trying to run the following Python code in command prompt: I'm using Python 2.
import zmq
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect('tcp://0.0.0.0.:6667')
socket.setsockopt_string(zmq.SUBSCRIBE, 'value')
and getting the following error when I execute:
socket.setsockopt_string(zmq.SUBSCRIBE, value) File "C:\Program Files\Anaconda2\lib\site-packages\zmq\sugar\socket.py", line 192, in >set_string raise TypeError("unicode strings only") TypeError: unicode strings only
can you pls advise on a solution ?
socket.setsockopt_string
acceptsunicode
string for optval.if you only run your code in python2, you should use
sock.setsockopt(zmq.SUBSCRIBE, b"value")
if you want to support both python2 and python3, you could use
Take a look at http://pyzmq.readthedocs.io/en/latest/unicode.html