2

I am trying to get header of the gRPC response with the following code, and it doesn't work:

response = stub.GetAccounts(users_pb2.GetAccountsRequest(), metadata=metadata)

header = response.header()

This is what this header looks like in Kreya, I'm trying to get it in python:

Header in Kreya

Does anyone know how to get the same header in python?

  • 1
    I suspect (! don't know) that you can't access the underlying HTTP/2 (response) headers from the (Python) gRPC client. You can configure various environment variables that expose underlying details (see [variables](https://github.com/grpc/grpc/blob/master/doc/environment_variables.md)) and perhaps `GRPC_TRACE="http" GRPC_VERBOSITRY="DEBUG"`. If the headers were actually gRPC metadata, you can use Python's `with_call` and `call.initial_metadata` and `call.trailing_metadata` as shown [here](https://github.com/grpc/grpc/blob/master/examples/python/metadata/metadata_client.py) – DazWilkin Jan 18 '22 at 21:52
  • @DazWilkin Yes, thanks a lot, using of with_call and call.initial_metadata is helped me – Драбышевский Никита Jan 18 '22 at 22:29
  • Great! I'll make the comment an answer. – DazWilkin Jan 18 '22 at 23:37

1 Answers1

1

I suspect (! don't know) that you can't access the underlying HTTP/2 (response) headers from the (Python) gRPC client.

You can configure various environment variables that expose underlying details (see gRPC environment variables) and perhaps GRPC_TRACE="http" GRPC_VERBOSITRY="DEBUG".

If the headers were actually gRPC metadata, you can use Python's with_call and call.initial_metadata and call.trailing_metadata as shown in the gRPC metadata example here.

DazWilkin
  • 32,823
  • 5
  • 47
  • 88