0
votes

I have a gRPC server written in c#. gRPC client is written in python. while I tested the C# client and it is working fine. createkey.proto

syntax = "proto3";
package CreateKey;


// The greeting service definition.
service CreateKey {

  rpc CreateKey(RequestCreateKey) returns (ReplyCreateKey);

}

message RequestCreateKey
{   
    string name = 1;
    int32  usage_mask = 2;
    string algorithm = 3;
}

message ReplyCreateKey
{
    string response = 1;
}

In C# client, I am able to parse the json file and able to call the function successfully. gRPC client code(c#)

using (StreamReader sr = new StreamReader("keygen.json"))
            {
                data = sr.ReadToEnd();   
            }
var writeKeyGen = JsonConvert.DeserializeObject<RequestCreateKey>(data);  
var response = client.CreateKey(writeKeyGen);

While in Python not able to call. Trying to call like:

gRPC client python code

    with grpc.insecure_channel('localhost:5005') as channel:
    response = ""
    stub = createkey_pb2_grpc.GreeterStub(channel)
    ##greeting = createkey_pb2_grpc.Greeting(first_name ="jiten",last_name ="M")
    ##request = createkey_pb2_grpc.GreetRequest(greeting = greeting)
    ##response = stub.Greet(request)

    # JSON file
    data = ""
    str = ""
    p = Path(__file__).with_name('keygen.json')
    with p.open('r') as f:
        # Reading from file
        str =f.read()
        data = json.loads(str)
    reqcreatekey = createkey_pb2_grpc.RequestCreateKey()
    response = stub.CreateKey(reqcreatekey)

So how to pass the json data in CreateKey function. Already checked that function calling is successful with the null data.