cruim
cruim

Reputation: 319

Protocol Buffers repeated field

I got this in my .proto file:

message Request {
    repeated string test = 2;
//    string test = 2;

}

There is a function:

def hash_md5(data):
    print(data)
    return data

There is a client code:

channel = grpc.insecure_channel('localhost:6066')
stub = mle_service_pb2_grpc.DataHashStub(channel)
text = ['Scio me nihil scire']
to_md5 = mle_service_pb2.Request(test=text)
response = stub.hash_md5(to_md5)
print('-----------',response)

But there is an exception Exception calling application: Assignment not allowed to repeated field "test" in protocol message object. If I change type in .proto forexample to string and change in client to text = ['Scio me nihil scire'] all works. How can I fix it with repeated type?

Upvotes: 2

Views: 22672

Answers (1)

DazWilkin
DazWilkin

Reputation: 40356

It's confusing (and bit me too) but you can't assign repeated fields (or messages) directly.

See Repeated Fields

Upvotes: 4

Related Questions