Skip to content Skip to sidebar Skip to footer

Send Plain Json To A Grpc Server Using Python

I'm able to send requests to one of our gRPC-enabled, reflection-enabled server using grpcurl with the following syntax: grpcurl --plaintext -d '{'test_input': 'Test 1 2 3', 'confi

Solution 1:

I think not because (the excellent) gRPCurl does not appear to provide an API|SDK that you'd want to be able to script it from Python.

As you note, this only works (without a proto or protoset) on gRPC servers that support reflection.

I think your approach of controlling gRPCurl through a shell is probably the best way. It may be worth a feature request to see whether others would like to drive gRPCurl as a test harness; it could be interesting.

Alternatively, if you're not wedded to gRPCurl, there may be other tools that support reflection that can be scrpted by Python. See:

https://github.com/grpc-ecosystem/awesome-grpc#tools-test

Solution 2:

gRPC uses HTTP2 in the transport layer. Just like any other RPC framework, it runs an http server which can be queried with basic http post requests. You can basically uses requests package to trigger a POST request to the gRPC server

import requests, jsonpayload= { "test_input": "Test 1 2 3", "config": { "max_results": 3 } }
response = requests.post("http://localhost:6565", data=json.dumps(payload))

Post a Comment for "Send Plain Json To A Grpc Server Using Python"