Protocol Buffers in Python 3 - NotImplementedError

I am trying to use the Google protocol buffers in a Python 3 project. However, the generated python files do not want to cooperate with the google.protobuf library. Attempting to use protobuf objects results in a NotImplementedError.

My setup:

  • Python 3.4.1
  • protoc 2.5.0

The problem occurs when using these libraries:

Example:

from pb_test import test_pb2
pb_object = test_pb2.TestMsg()
pb_object.Clear()  # results in NotImplementedError

, , - test_pb2.py. " " , . , .

test.proto:

message TestMsg {
  required int32 id = 1;
}

:

eipifi@debvm:~/pb_test$ protoc --python_out=. test.proto

.

+4
1

. * _pb2.py protobuf Python 3, :

:

class TestMsg(_message.Message):
__metaclass__ = _reflection.GeneratedProtocolMessageType
DESCRIPTOR = _TESTMSG

Fixed

class TestMsg(_message.Message, metaclass=_reflection.GeneratedProtocolMessageType):
DESCRIPTOR = _TESTMSG
+3

All Articles