I am trying to setup an example Python gRPC example and have following proto file :
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);
}
The project structure is :
|- greet.protos
When I try running protoc using below :
python -m grpc_tools.protoc -I./protos --python_out=. --grpc_python_out=. ./protos/greet.proto
I get the error below:
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 list confirms I have the available packages:
(grpcenv) (base) ➜ Greeter pip list Package Version
grpcio 1.51.1 grpcio-tools 1.51.1 pip 22.3.1 protobuf 4.21.12 setuptools 57.0.0 wheel 0.36.2
I was reviewing the code and found the issue i.e. the proto was incorrect or rather incomplete.
The below proto resolved the issue (and the error was exactly what the problem was !!!)
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;
}