【问题标题】:python proto is not generating classes?python proto 不生成类?
【发布时间】:2022-10-06 15:24:33
【问题描述】:

我正在尝试使用这样的原型从原型文件生成 python 代码。

syntax=\"proto3\";

service EmailInferencing {
  rpc Infer (EmailInferRequest) returns (EmailInferResponse) {}
}

// ######## Email Infer ########

message Embeddings {
    repeated int64 feature = 1;
}

message EmailInferRequest {
  repeated string model_names = 1;
  string customer_id = 2;
  repeated Embeddings embeddings = 3;
}

message EmailInferResponse {
  repeated string labels = 1;
}

我收到的 pb2.py 文件看起来像这样

# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: infer.proto
\"\"\"Generated protocol buffer code.\"\"\"
from google.protobuf.internal import builder as _builder
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)

_sym_db = _symbol_database.Default()




DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b\'\\n\\x0binfer.proto\\x12\\x05\\x65mail\\\"\\x1d\\n\\nEmbeddings\\x12\\x0f\\n\\x07\\x66\\x65\\x61ture\\x18\\x01 \\x03(\\x03\\\"d\\n\\x11\\x45mailInferRequest\\x12\\x13\\n\\x0bmodel_names\\x18\\x01 \\x03(\\t\\x12\\x13\\n\\x0b\\x63ustomer_id\\x18\\x02 \\x01(\\t\\x12%\\n\\nembeddings\\x18\\x03 \\x03(\\x0b\\x32\\x11.email.Embeddings\\\"$\\n\\x12\\x45mailInferResponse\\x12\\x0e\\n\\x06labels\\x18\\x01 \\x03(\\t2R\\n\\x10\\x45mailInferencing\\x12>\\n\\x05Infer\\x12\\x18.email.EmailInferRequest\\x1a\\x19.email.EmailInferResponse\\\"\\x00\\x62\\x06proto3\')

_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, \'infer_pb2\', globals())
if _descriptor._USE_C_DESCRIPTORS == False:

  DESCRIPTOR._options = None
  _EMBEDDINGS._serialized_start=22
  _EMBEDDINGS._serialized_end=51
  _EMAILINFERREQUEST._serialized_start=53
  _EMAILINFERREQUEST._serialized_end=153
  _EMAILINFERRESPONSE._serialized_start=155
  _EMAILINFERRESPONSE._serialized_end=191
  _EMAILINFERENCING._serialized_start=193
  _EMAILINFERENCING._serialized_end=275
# @@protoc_insertion_point(module_scope)

这有 EmailInferRequestEmailInferResponse 缺失,我可以将它们导入到我的 server.py 文件中。

对于原型生成,我使用以下代码:

python3 -m grpc_tools.protoc -I.  infer.proto  --python_out=. --grpc_python_out=.

这个问题类似于this,但是我在命令中添加了标志,但还是有问题。

  • 请参阅此answer。您的protopython3 -m grpc_tools.protoc 和生成的_pb2.py 文件都是正确的。如果您编写利用服务和消息的代码,它将要正常工作。令人困惑的是 Python 中 gRPC|protobuf 实现的本质。

标签: python grpc grpc-python


【解决方案1】:

好的,是的..生成的文件是正确的,只是生成的文件的结构最近发生了变化。我尝试使用它,并且从生成的文件中导入的工作方式与以前的工作方式相同。这意味着,您可以像以前一样继续使用它们,而不必介意生成文件的外观。谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 2020-01-05
    • 2016-12-08
    相关资源
    最近更新 更多