Tony Jiang
Tony Jiang

Reputation: 21

Why can't I use protoc generate Python3 object which has an Any type field via --python3_out, only --python_out works

I created a proto file RpcCmd.proto, and defined one field with type google.protobuf.Any, when I tried to generate a Python3 object file with cmd protoc --python3_out=./gen RpcCmd.proto it failed with error

Traceback (most recent call last):
  File "/usr/local/bin/protoc-gen-python3", line 36, in <module>
    compiler = Compiler(desc_map[file_name], top_level_elements)
  File "/usr/local/lib/python3.7/site-packages/protobuf3/compiler/__init__.py", line 54, in __init__
    self.process_message(message)
  File "/usr/local/lib/python3.7/site-packages/protobuf3/compiler/__init__.py", line 104, in process_message
    self.process_field(message.name, field, embedded)
  File "/usr/local/lib/python3.7/site-packages/protobuf3/compiler/__init__.py", line 148, in process_field
    file_to_import = splitext(self.__tle_map[top_level_name])[0].replace('/', '.')
KeyError: 'google'
--python3_out: protoc-gen-python3: Plugin failed with status code 1.

But, if I typed with cmd protoc --python_out=. RpcCmd.proto it succeeded

I also tried --java_out worked without any error.

syntax = "proto3";
import "google/protobuf/any.proto";

message RpcCmd {
    google.protobuf.Any message = 1;
    string randomKey = 2;
}

Is it possible to use type Any with --python3_out?

Upvotes: 2

Views: 646

Answers (0)

Related Questions