Python gRPC请求〈>回复未定义

q5iwbnjs  于 2023-01-03  发布在  Python
关注(0)|答案(1)|浏览(117)

我正在尝试设置一个示例Python gRPC示例,并具有以下proto文件:

syntax = "proto3";

package greet;

service Greeter{

  // unary
  rpc SayHello (HelloRequest) returns (HelloReply);

  // Server Streaming
  rpc ParrotSayHello (HelloRequest) returns (stream HelloReply);

  // Client Streaming
  rpc ChattyClientSayHello (stream HelloRequest) returns (DelayedReply);

  // Both Streaming
  rpc InteractingHello (stream HelloReequest) returns (stream HelloReply);

}

项目结构为:

  • 格雷特
  • |- 原型
|- greet.protos

当我尝试使用以下命令运行协议时:

python -m grpc_tools.protoc -I./protos --python_out=. --grpc_python_out=. ./protos/greet.proto

我得到下面的错误:

greet.proto:8:17: "HelloRequest" is not defined.
greet.proto:8:40: "HelloReply" is not defined.
greet.proto:11:23: "HelloRequest" is not defined.
greet.proto:11:53: "HelloReply" is not defined.
greet.proto:14:36: "HelloRequest" is not defined.
greet.proto:14:59: "DelayedReply" is not defined.
greet.proto:17:32: "HelloReequest" is not defined.
greet.proto:17:63: "HelloReply" is not defined.

Pip列表确认我有可用的软件包:
(grpcenv)(base)问候语pip list软件包版本
图形输入输出1.51.1图形输入输出工具1.51.1 pip 22.3.1协议缓冲区4.21.12设置工具57.0.0滚轮0.36.2

km0tfn4u

km0tfn4u1#

我正在查看代码,发现了这个问题,即原型不正确或不完整。
下面的proto解决了这个问题(错误正是问题所在!!!)

syntax = "proto3";

package greet;

// The greeting service definition.
service Greeter {
    // Unary
    rpc SayHello (HelloRequest) returns (HelloReply);

    // Server Streaming
    rpc ParrotSaysHello (HelloRequest) returns (stream HelloReply);
    
    // Client Streaming
    rpc ChattyClientSaysHello (stream HelloRequest) returns (DelayedReply);

    // Both Streaming
    rpc InteractingHello (stream HelloRequest) returns (stream HelloReply);
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
  string greeting = 2;
}

// The response message containing the greetings.
message HelloReply {
  string message = 1;
}

message DelayedReply {
    string message = 1;
    repeated HelloRequest request = 2;
}

相关问题