Bytes array
or utf8 strings
.def SayHello(self, request, context):
# request might be a byte array or a utf8 string
= HelloRequest.HelloRequest().GetRootAs(request, 0)
r = "Unknown"
reply if r.Name():
= r.Name()
reply # Issues might happen if type checking isnt present.
# thus encoding it as a `reply.decode('UTF-8')`
return build_reply("welcome " + reply.decode('UTF-8'))
This can be prevented by making sure all the requests coming to/from
python are Bytes array
def say_hello(stub, builder):
= bytes(builder.Output())
hello_request = stub.SayHello(hello_request)
reply = HelloReply.HelloReply.GetRootAs(reply)
r print(r.Message())
content-type
of the payload to be
set to application/grpc+flatbuffers
example:
.SayHello(ctx, b, grpc.CallContentSubtype("flatbuffers"))