pyzmq
pyzmq copied to clipboard
TypeError when running mdclient from guide examples
Working through the examples I came across the following error in chapter 4 (majordomo pattern). Python version is 3.6.5 and:
Current libzmq version is 4.1.6 Current pyzmq version is 17.0.0
% python mdclient.py
Traceback (most recent call last):
File "/Users/twry/development/zguide/examples/Python/env/lib/python3.6/site-packages/zmq/sugar/socket.py", line 426, in send_multipart
memoryview(msg)
TypeError: memoryview: a bytes-like object is required, not 'str'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "mdclient.py", line 29, in <module>
main()
File "mdclient.py", line 18, in main
reply = client.send("echo", request)
File "/Users/twry/development/zguide/examples/Python/mdcliapi.py", line 67, in send
self.client.send_multipart(request)
File "/Users/twry/development/zguide/examples/Python/env/lib/python3.6/site-packages/zmq/sugar/socket.py", line 433, in send_multipart
i, rmsg,
TypeError: Frame 0 ('MDPC01') does not support the buffer interface.
Now I'm stuck with this. Any help would be much appreciated.
Hi I think your problem is related to what described in "Bytes and strings" paragraph here: https://pyzmq.readthedocs.io/en/latest/pyversions.html
try putting b in front of strings, such as b'echo' or encoding them :
reply = client.send(b"echo", request.encode())
Probably there are a few changes to make in the various files in order to get it to work with python 3.5
Right, I had to make changes to MDP.py and mdcliapi.py, too. Now I'm not getting no error message any more but also no output, will need to debug some more... thanks!
libzmq-4.2.5 pyzmq-17.1.2 Python-3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
Same for me. This is actually an issue with the examples in the zguide not being compatible with Python3 and not pyzmq itself.
Created new issue for the zguide zguide-issue-#747
You have to find all strings that are sent through and change them to bytes. e.g. in MDP.py
W_READY = "\001"
becomes
W_READY = b"\001"
Other things to search for are empty strings ('' or "") change to (b'' or b"")