http headers in GRPC python call

605 views
Skip to first unread message

Tejal Singh

unread,
Jul 5, 2022, 5:03:17 AM7/5/22
to grpc.io
Hi

I want to know how we can add custom http headers in a grpc call. I am using feast serving service stub for making grpc call (from feast.serving.ServingService_pb2_grpc import ServingServiceStub).

Adrian Gay

unread,
Jul 5, 2022, 6:18:57 AM7/5/22
to grpc.io
headers are passed as gRPC metadata. So, on a stub call, there is an additional argument. A Python binding example:

response = stub.Predict(request, timeout=self.timeout, metadata=metadata)

metadata is a sequence of Tuples. For headers, the Tuple value at index 0 is the HTTP header key and at index 1 is the HTTP header value.

Adrian

Adrian Gay

unread,
Jul 5, 2022, 6:23:28 AM7/5/22
to grpc.io
following on from previous reply, here is an example of metadata viewed in VSCode debugger:

metadata-vscode-debugger.png

Reply all
Reply to author
Forward
0 new messages