Im trying to get the status code from the client in gRPC when the response is successful with python. Similar to REST API when you do response.status_code == 200
. I need to assert that is a successful call
I've tried unpacking the response by doing. This is the code structure, not the actual one
reposonse, metadata, code = stub.{Mygrpc}(request, metada)
print(code)
but what I only need is to get the status code in Python.
response = onboarding_stub.AnswerEmailChallenge(request=answer_email_request,
metadata=[('authorization', get_token)])
I would like to see the grpc.Status_code.OK display in console from that call. I don't know which function from which package to use to get the status code.
A grpc.RpcError
is raised to indicate non-OK grpc status code. You can catch the exception to print status code.
try:
response = onboarding_stub.AnswerEmailChallenge(request=answer_email_request,
metadata=[('authorization', get_token)])
except grpc.RpcError as e:
print(e.code())
else:
print(grpc.StatusCode.OK)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.