The repeated field of protobuf message is always empty on the gRPC client
side even though I set it on the gRPC server side.
Is there any way to fix this issue?
- helloworld.proto file:
syntax = "proto3";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting.
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings.
message HelloReply {
string message = 1;
repeated string snippets = 2;
}
- server.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from concurrent import futures
import time
import grpc
import grpc_demo.lib.protos.helloworld_pb2 as helloworld_pb2
import grpc_demo.lib.protos.helloworld_pb2_grpc as helloworld_pb2_grpc
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
reply = helloworld_pb2.HelloReply(message='Hello, %s!' % request.
name)
reply.snippets.append('test-snippets')
# print('reply:' + reply)
return reply
def main():
"""Main entrance."""
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
main()
- client.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import grpc
import grpc_demo.lib.protos.helloworld_pb2 as helloworld_pb2
import grpc_demo.lib.protos.helloworld_pb2_grpc as helloworld_pb2_grpc
def main():
"""Main entrance."""
# NOTE(gRPC Python Team): .close() is possible on a channel and
should be
# used in circumstances in which the with statement does not fit the
needs
# of the code.
with grpc.insecure_channel('localhost:50051') as channel:
stub = helloworld_pb2_grpc.GreeterStub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
print("Greeter client received: " + response.message + ',
'.join(response.snippets)
+ str(len(response.snippets)))
if __name__ == '__main__':
main()
- Expected Result:
*Greeter client received: Hello, you!test-snippets1*
- Actual Result:
*Greeter client received: Hello, you!0*
Thanks!
Jiongjiong Li
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/621d0a95-d098-4b93-9ac4-45a1e82abdb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.