python - 属性错误 : Assignment not allowed to composite field "task" in protocol message object

标签 python protocol-buffers

我正在使用protocol-buffers python lib发送数据,但它有一些问题,所以

Traceback (most recent call last):
  File "test_message.py", line 17, in <module>
    ptask.task = task
  File "build\bdist.win32\egg\google\protobuf\internal\python_message.py", line
513, in setter
AttributeError: Assignment not allowed to composite field "_task" in protocol message object.

src如下:

原型(prototype)文件:

message task {
    required int32 id = 1;
    required string msg = 2;
}

message task_info {
    required task task = 1;
}

python 代码:

task = yacc.task()
task.id = 1000
task.msg = u"test"
ptask = yacc.task_info() 
ptask.task = task # this line happen the runtime error 

最佳答案

试试 CopyFrom :

ptask.task.CopyFrom(task)

关于python - 属性错误 : Assignment not allowed to composite field "task" in protocol message object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18376190/

相关文章:

go - go 的 protobuf 实现是否支持 DynamicMessage?

c++ - 为什么我的 protobuf 反序列化给出空负载?

protocol-buffers - protoc 不生成服务 stub 文件

python - 遍历目录,删除

python - 在 python 中生成使用 RSA key 签名的 JWT token

python - PyCharm如何继承抽象类

python - 将列添加到 pandas 数据框中,其中包含每行的最大值以及相应的列名称

python - 在 pandas/ipython 中选择特定的 excel 行进行分析?

用于解析包含数组格式的 protobuf 数据的二进制文件的 Python API

protocol-buffers - 安装 Python Protocol Buffers 的问题