Reputation: 23
I want to build a protobuf message on protobuf's API on python. Here is my proto file. But I can't add "D" in my code.
package pkg;
message A
{
repeated B b = 1;
}
message B
{
C c = 1;
}
message C
{
enum D {
OPTION1 = 1;
OPTION2 = 2;
}
repeated D d = 1;
}
Here is my python code.
my_A = A()
my_B = my_A.b.add()
my_B.c.add(D.OPTION1)
Here is what i got:
AttributeError: 'RepeatedScalarFieldContainer' object has no attribute 'add'
Upvotes: 2
Views: 5805
Reputation: 116
I encounter this error and after hours of googling, I found this https://www.programcreek.com/python/example/96615/google.protobuf.internal.containers.RepeatedScalarFieldContainer Example 1 shows a RepeatedScalarFieldContainer
value use append()
. So try append may work.
Upvotes: 10