Skip to content

Instantly share code, notes, and snippets.

@fzankl
Created January 24, 2021 09:23
Show Gist options
  • Save fzankl/0aba8e7c759bf11fc7d969771fdcb12a to your computer and use it in GitHub Desktop.
Save fzankl/0aba8e7c759bf11fc7d969771fdcb12a to your computer and use it in GitHub Desktop.
gRPC request using Python
import grpc
# Import dependencies generated by gRPC tools
import foo_pb2
import foo_pb2_grpc
def get_foo(stub):
foo = stub.GetFoo(foo_pb2.FooRequest(message = "Sample request"))
print("GetFoo called %s" % (foo.message))
def run():
# Secured channel using dotnet dev certificate
credential = grpc.ssl_channel_credentials(open('localhost.pem', 'rb').read())
with grpc.secure_channel('localhost:5001', credential) as channel:
stub = foo_pb2_grpc.FooServiceStub(channel)
print("-------------- GetFoo --------------")
get_foo(stub)
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment