[Tutor] Serializing bytestring as JSON
Mats Wichmann
mats at wichmann.us
Mon Aug 10 09:30:18 EDT 2020
On 8/9/20 9:04 PM, S D wrote:
> Hi. If you're reading this, I hope you're healthy and safe.
>
> I built an RPC service based on the Nameko framework. The service class
> implements a method which takes a list of strings as an argument and
> returns a dictionary with each original string as a key and the string
> Huffman encoded as a value. The encoding works, but I cannot send the
> return value across the network because the encoded bytestrings cannot be
> serialized to JSON.
>
> If I import the service class and test the methods using PyTest, this
> problem is not reproduced.
>
> How can I return a Huffman encoded bytestring over a wire as JSON?
Just a question to think about: are you sure you actually want JSON to
be your over-the-wire encoding? It's human-readable, yes, but adds a
fair bit of bulk, and is not sufficient for directly encoding Python
datastructures, although you can make _anything_ work with enough effort.
More information about the Tutor
mailing list