Я хочу протестировать вложенное сообщение на API protobuf на python.объект не имеет атрибута 'add' на protobuf python
Мой файл прото ndemo.proto
был:
package ndemotest;
message BaseRequest
{
required bytes Key = 1;
}
message ContRequest
{
required BaseRequest baseRequest = 1;
optional string Url = 2;
}
Мой питон ndemo.py
код был:
import binascii
import ndemo_pb2
contReq = ndemo_pb2.ContRequest()
contReq.Url="www.google.com"
base_request = contReq.baseRequest.add()
base_request.Key="12345"
packed_data = contReq.SerializeToString()
print 'sending "%s"' % binascii.hexlify(packed_data)
Когда я побежал мой сценарий как python ndemo.py
, произошла ошибка
Traceback (most recent call last): File "ndemo.py", line 8, in base_request = contReq.baseRequest.add() AttributeError: 'BaseRequest' object has no attribute 'add'