use python load proto files to mock server error

Skip to first unread message

Aug 1, 2022, 10:16:06 AMAug 1
Hi there!
I'm actually facing some issues and am wondering if I'm on a completely wrong track here. We're currently trying to make a common mock server used by python + grpc +proto with experimental no-codegen API:

However, we're currently facing the issues that load some proto files which we addressed like this:
for root, dirs, files in os.walk(path):
    for file in files:
        if '.proto' in file:
            try:                _proto, _services = grpc.protos_and_services(file)
            except Exception as e:
                logger.error("Error: grpc.protos_and_services error {}, proto file {}".format(e, file))
                raise e            service_list = inspect.getmembers(_services, inspect.isfunction)
            for (module_name, module_instance) in inspect.getmembers(_services, inspect.isclass):
                if 'Servicer' in module_name:
                    service_dict[module_name.split("Servicer")[0]] = (
                        _services, module_instance, [x[1] for x in service_list if module_name in x[0]][0],

return service_dict

the error msg:
    return _message.default_pool.AddSerializedFile(serialized_pb)
TypeError: Couldn't build proto file into descriptor pool!
Invalid proto descriptor for file "clarity.proto":
  live.xanchor.v1.Virtual: "live.xanchor.v1.Virtual" is already defined in file "virtual.proto".
  live.xanchor.v1.Virtual: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it.  Therefore, "Virtual" must be unique within "live.xanchor.v1", not just within "ClarityLiveMode".

the clarity.proto like this:
enum ClarityLiveMode {
    ...    Virtual = 5;      }

the virtual.proto like this:
service Virtual {
    rpc ...

How can I load proto files, and avoid this issue? thanks.




This message may contain confidential information, and is intended only for the use of the addressee(s) named above. If you have received this message in error, please contact the sender immediately and delete all copies from your system. You are hereby notified that any dissemination, distribution, preservation or copying of this message and/or attachments is strictly prohibited. Thank you for your understanding and cooperation.

Reply all
Reply to author
0 new messages