How can ı reach grpc request headers in python?

1,077 views
Skip to first unread message

Cihad Ceviz

unread,
May 20, 2021, 11:14:39 AM5/20/21
to grpc.io
Hello, I'm a newbie in the world of grpc and coding. If my question is ridiculous, I apologize in advance.

Question: There is a token that we have defined in X. And I have to decide whether to run transactions using this token. I can receive the incoming request correctly, but I don't know how to access the headers part of this request. Is it possible to reach the variable that I define the request by typing ".headers" as in the RESTFUL API architecture? What should I do? Can you help me?

Thank You, Good Work

If I need to share my code block:

` def UDTForegroundApp(self, request, context):
        apiRequest = {
            "Token": I need to put the token in the request here
              ....
              ....
              ....
              ....
        }
        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        requests.post('http://*****/api/auth/save-application', data=json.dumps(apiRequest), headers=headers)
        return generatedProtos.application_pb2.DTForegroundAppResponse(ret_complete = services.config.foreground_application_ret_complete) `

Lidi Zheng

unread,
May 20, 2021, 1:15:49 PM5/20/21
to Cihad Ceviz, grpc.io
Hi Cihad,

Here is an example of metadata (aka. HTTP Headers) usage in gRPC Python: https://github.com/grpc/grpc/tree/master/examples/python/metadata.

If you just started to use gRPC Python, I would suggest to read our guide: https://grpc.io/docs/languages/python/
For question about certain API usage, you may found API reference useful: https://grpc.github.io/grpc/python/index.html


--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/018258c9-8062-456e-a327-1e1b0eac8070n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages