0

I have the below grpc request which is working fine with Postman:-

URL :- 10.91.151.107:30105

Payload :- {
    "headend": { "v4": 173768306 },
    "tailend": { "v4": 173768309 },
    "dataplane": "DATAPLANE_MPLS",
    "o_metric": "METRIC_TYPE_IGP",
    "constraints": { "unprotected_segments": true ,"max_segments":10 ,"return_path_max_segments":10 },
    "corouted_return_path": true
}

There is no proto buf imported for the above request. I can using it is using the server reflection to get "Unary" as "StatelessCalc/SinglePath"

enter image description here

How can I invoke the same request with python from pycharm?

from grpc_requests import Client

client = Client.get_by_endpoint("localhost:50051")
assert client.service_names == ["helloworld.Greeter"]

request_data = {"name": "sinsky"} 
say_hello_response = client.request("helloworld.Greeter", "SayHello", request_data)
assert say_hello_response ==  {"message":"Hello sinsky!"}

1 Answer 1

0

The following code should replicate the method call:

from grpc_requests import Client

endpoint = "10.91.151.107:30105"
service = "srs.te_calc.v1.StatelessCalc"
method = "SinglePath",

client = Client.get_by_endpoint(
    endpoint,
    ssl=False,
)

assert set(client.service_names) == set([
    "grpc.health.v1.Health",
    "grpc.reflection.v1.ServerReflection",
    service,
]), "Failed"

rqst = {
    "headend": {
        "v4": 173768306
    },
    "tailend": {
        "v4": 173768309
    },
    "dataplane": "DATAPLANE_MPLS",
    "o_metric": "METRIC_TYPE_IGP",
    "constraints": {
        "unprotected_segments": true,
        "max_segments": 10,
        "return_path_max_segments": 10
    },
    "corouted_return_path": true
}
resp = client.request(
    service,
    method,
    rqst,
)
print(resp)
Sign up to request clarification or add additional context in comments.

4 Comments

I have tried the same , but it didn't work as expected. It is giving the follwoing error : File "C:\pythonProject1\test_blacklist\sra_grpc_requests.py", line 7, in <module> client = Client.get_by_endpoint(endpoint,ssl=False) File "C:\pythonProject1\venv\Lib\site-packages\grpc_requests\client.py", line 139, in get_by_endpoint _cached_clients[endpoint] = cls(endpoint, **kwargs) File "C:\pythonProject1\venv\Lib\site-packages\grpc_requests\client.py", line 505, in init self.register_all_service()
File "C:\pythonProject1\venv\Lib\site-packages\google\protobuf\json_format.py", line 570, in _ConvertFieldValuePair raise ParseError( google.protobuf.json_format.ParseError: Message type "srs.te_calc.v1.SinglePathRequest" has no field named "backend" at "SinglePathRequest". Available Fields(except extensions): "['headend', 'tailend', 'dataplane', 'oMetric', 'constraints', 'coroutedReturnPath']" The above exception was the direct cause of the following exception:
Oh my mistake, update answer with r/backend/tailend
You're welcome! I'm pleased to hear that it helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.