dict keys form python2 server returns as bytes in python3 client

27 views
Skip to first unread message

Shiplu Mokaddim

unread,
Oct 9, 2019, 5:07:55 PM10/9/19
to zerorpc
So I have this server.


import zerorpc

class MyServer(object):
    def method(self):
        print("method is called")
        return {'key': 'value'}

server = zerorpc.Server(MyServer(), heartbeat=None)

server.bind("tcp://0.0.0.0:9999")


try:
    zerorpc.gevent.spawn(server.run)
    while True:
        zerorpc.gevent.sleep(1)
except KeyboardInterrupt:
    print("KeyboardInterrupt Received!")
    server.close()



I run it with python2 `python2 s.py`

Then on a different terminal, I call the method with python3 virtual environment. And I get this result


(zerorpc) $ python3 ~/venv/zerorpc/bin/zerorpc tcp://0.0.0.0:9999 method
connecting to "tcp://0.0.0.0:9999"
{b'key': b'value'}

I expected this to be {'key': 'value'}. How can I get the expected value?

I have a workaround in place. I return everything in JSON encoded string. And then on the client-side, I decode it. But I really don't want to perform encoding myself as It's been done on the wire-level of zerorpc.

In python3 (3.6.3) I have these packages.

future==0.17.1
gevent==1.3.7
msgpack-python==0.5.6
pyzmq==17.1.0
zerorpc==0.6.1

In python2 (2.7.12) I have these

future==0.16.0
gevent==1.3.5
msgpack-python==0.5.6
pyzmq==17.1.0
zerorpc==0.6.1




François-Xavier Bourlet

unread,
Oct 10, 2019, 3:26:06 AM10/10/19
to zerorpc
read this: https://portingguide.readthedocs.io/en/latest/strings.html
> --
> You received this message because you are subscribed to the Google Groups "zerorpc" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to zerorpc+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/zerorpc/fd2ce988-fc60-4bc7-a88f-8d98ca373c0e%40googlegroups.com.

shiplu

unread,
Oct 10, 2019, 8:03:01 AM10/10/19
to zer...@googlegroups.com
Thanks, François for the link. I discovered it when I put a mixture of both str and Unicode in dict. 
If I use  [{u'key': u'value'}, {'key': 'value'}], The result is [{'key': 'value'},  {b'key': b'value'}]. it means I have to encode my string literales manually (either calling .encode() or use `u` prefix).

Thanks again for your help

You received this message because you are subscribed to a topic in the Google Groups "zerorpc" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/zerorpc/6snTKbGHdNo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zerorpc+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zerorpc/CAG9r-Dbpi4DjCbU496Cz9TgGkmzWYf3NHrMk-KAgB5E2MvZuig%40mail.gmail.com.


--
Shiplu.Mokadd.im
Unix Hacker


Innovation distinguishes between follower and leader

—  Steve Jobs

An expert is a person who has made all the mistakes that can be made in a very narrow field.
— Neils Bohr

François-Xavier Bourlet

unread,
Oct 10, 2019, 3:09:23 PM10/10/19
to zerorpc
Reply all
Reply to author
Forward
0 new messages