Send Plain Json To A Grpc Server Using Python
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:
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"