Hi I am trying to write a test grpc client and service in python. When I use an insecure channel, everything works stably, but if I try to establish a tls connection, an error occurs. To write code and create a chain of certificates, I used this guide https://github.com/joekottke/python-grpc-ssl.How can I make this example work?
grpcio version : 1.51.1 python version 3.9.17
Error message -
Message = <_InactiveRpcError of RPC that terminated with:
-
status = StatusCode.UNAVAILABLE
-
details = "failed to connect to all addresses"
-
debug_error_string = "{"created":"@1690999363.720000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3094,"referenced_errors":[{"created":"@1690999363.720000000","description":"failed to connect to all addresses","file":"src/core/lib/transport/error_utils.cc","file_line":163,"grpc_status":14}]}"
-
>
-
Source = F:\Work\PytService\ClientPy\ClientPy.py
-
Stack trace:
-
File "F:\Work\PytService\ClientPy\ClientPy.py", line 22, in run
-
response = stub.SayHello(service_pb2.HelloRequest(name='you'))
-
File "F:\Work\PytService\ClientPy\ClientPy.py", line 32, in <module> (Current frame)
-
run()
-
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
-
status = StatusCode.UNAVAILABLE
-
details = "failed to connect to all addresses"
-
debug_error_string = "{"created":"@1690999363.720000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3094,"referenced_errors":[{"created":"@1690999363.720000000","description":"failed to connect to all addresses","file":"src/core/lib/transport/error_utils.cc","file_line":163,"grpc_status":14}]}"
-
>
-
Service code -
from concurrent import futures
-
import logging
-
import grpc
-
import service_pb2
-
import service_pb2_grpc
-
-
-
class Greeter(service_pb2_grpc.GreeterServicer):
-
-
def SayHello(self, request, context):
-
return service_pb2.HelloReply(message='Hello, %s!' % request.name)
-
def SayHelloAgain(self, request, context):
-
return service_pb2.HelloReply(message=f'Hello again, {request.name}!')
-
-
def serve():
-
port = '50051'
-
server_host = 'localhost'
-
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
-
service_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
-
-
keyfile = 'server-key.pem'
-
certfile = 'server-cert.pem'
-
private_key = open(keyfile).read()
-
certificate_chain = open(certfile).read()
-
credentials = grpc.ssl_server_credentials(
-
((bytes(private_key, 'utf-8'), bytes(certificate_chain, 'utf-8'),),)
-
)
-
server.add_secure_port('localhost:50001',credentials)
-
server.start()
-
print("Server started, listening on " + port)
-
server.wait_for_termination()
-
-
-
if __name__ == '__main__':
-
logging.basicConfig()
-
serve()
-
Client code -
from __future__ import print_function
-
import logging
-
import grpc
-
import grpc_tools
-
import service_pb2
-
import service_pb2_grpc
-
-
-
def run():
-
ca_cert = 'ca-cert.pem'
-
root_certs = open(ca_cert).read()
-
credentials = grpc.ssl_channel_credentials((bytes(root_certs, 'utf-8')))
-
with grpc.secure_channel('localhost:50051',credentials) as channel:
-
stub = service_pb2_grpc.GreeterStub(channel)
-
response = stub.SayHello(service_pb2.HelloRequest(name='you'))
-
print("Greeter client received: " + response.message)
-
response = stub.SayHelloAgain(service_pb2.HelloRequest(name='you1'))
-
print("Greeter client received: " + response.message)
-
-
-
if __name__ == '__main__':
-
logging.basicConfig()
-
run()
-
I tried to change certificates, creating them not only according to the manual, but also using openssl. And also change the encryption method for certificates from RSA to P-256 curve. But none of the above helped.
0 3956 Sign in to post your reply or Sign up for a free account.
Similar topics
by: jtd |
last post by:
Hi all,
I'm using asyncore to download a large list of web pages, and I've
noticed dispatcher.connect blocks for some hosts. I was under the
impression that non-blocking sockets do not block on...
|
by: Simon Jefferies |
last post by:
Hello,
I'm trying to create a new ASP. NET Web Application project, when I enter a
name and press OK i get the following:
Web Access Failed.
The default web access mode for this project is...
|
by: Hawksey |
last post by:
Hello,
Has anyone else experienced a similar problem.
We get an intermittent error trying to send mail using smtpmail.
Our SmtpMail.SmtpServer is a different server to our web application...
|
by: Marcus |
last post by:
I have a function that simply returns TRUE if it can connect to a
particular Sql Server 2005 express, or FALSE if it cannot. I am getting
some strange error codes returned when the computer that...
|
by: comp.lang.php |
last post by:
I came up with functions that I thought would do the trick:
if (!function_exists('smtp_close')) {
/**
* This function will close a socket resource handle
*
* Original function found at...
|
by: wizromeo |
last post by:
Hello,
Has anyone else experienced a similar problem.
We get an intermittent error trying to send mail using smtpmail.
Our SmtpMail.SmtpServer is a different server to our web application...
|
by: valeberry |
last post by:
//Index.php
<html><head><title>Mailing List Administration</title></head><body>
<br>
<center><H1>Mailing List Administration</H1></center>
Send an email to a mailing list:
<form method=post...
|
by: =?Utf-8?B?U2VyZ2Vp?= |
last post by:
Dear staff
Can I get your assistance with \3GB (LARGEADDRESSAWARE) switch in mixed mode
process built by VS 2008, please?
I have a mixed mode application: C# GUI calling native C++ DLL through...
|
by: deva5499 |
last post by:
Hi, I am getting this error when we are running a job called Post load scripts In datastage. From routines we are calling the shellscripts then the Shells scripts calling thejavaclass followed by...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |