473,416 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

InactiveRpcError failed to connect to all addresses

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
Expand|Select|Wrap|Line Numbers
  1. Message = <_InactiveRpcError of RPC that terminated with:
  2.     status = StatusCode.UNAVAILABLE
  3.     details = "failed to connect to all addresses"
  4.     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}]}"
  5. >
  6.   Source = F:\Work\PytService\ClientPy\ClientPy.py
  7.   Stack trace:
  8.   File "F:\Work\PytService\ClientPy\ClientPy.py", line 22, in run
  9.     response = stub.SayHello(service_pb2.HelloRequest(name='you'))
  10.   File "F:\Work\PytService\ClientPy\ClientPy.py", line 32, in <module> (Current frame)
  11.     run()
  12. grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
  13.     status = StatusCode.UNAVAILABLE
  14.     details = "failed to connect to all addresses"
  15.     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}]}"
  16. >
  17.  
Service code

Expand|Select|Wrap|Line Numbers
  1. from concurrent import futures
  2. import logging
  3. import grpc
  4. import service_pb2
  5. import service_pb2_grpc
  6.  
  7.  
  8. class Greeter(service_pb2_grpc.GreeterServicer):
  9.  
  10.     def SayHello(self, request, context):
  11.         return service_pb2.HelloReply(message='Hello, %s!' % request.name)
  12.     def SayHelloAgain(self, request, context):
  13.         return service_pb2.HelloReply(message=f'Hello again, {request.name}!')
  14.  
  15. def serve():
  16.     port = '50051'
  17.     server_host = 'localhost'
  18.     server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
  19.     service_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
  20.  
  21.     keyfile = 'server-key.pem'
  22.     certfile = 'server-cert.pem'
  23.     private_key = open(keyfile).read()
  24.     certificate_chain = open(certfile).read()
  25.     credentials = grpc.ssl_server_credentials(
  26.        ((bytes(private_key, 'utf-8'), bytes(certificate_chain, 'utf-8'),),)
  27.     )
  28.     server.add_secure_port('localhost:50001',credentials)
  29.     server.start()
  30.     print("Server started, listening on " + port)
  31.     server.wait_for_termination()
  32.  
  33.  
  34. if __name__ == '__main__':
  35.     logging.basicConfig()
  36.     serve()
  37.  
Client code
Expand|Select|Wrap|Line Numbers
  1. from __future__ import print_function
  2. import logging
  3. import grpc
  4. import grpc_tools
  5. import service_pb2
  6. import service_pb2_grpc
  7.  
  8.  
  9. def run():
  10.       ca_cert = 'ca-cert.pem'
  11.       root_certs = open(ca_cert).read()
  12.       credentials = grpc.ssl_channel_credentials((bytes(root_certs, 'utf-8')))
  13.       with grpc.secure_channel('localhost:50051',credentials) as channel:
  14.           stub = service_pb2_grpc.GreeterStub(channel)
  15.           response = stub.SayHello(service_pb2.HelloRequest(name='you'))
  16.           print("Greeter client received: " + response.message)
  17.           response = stub.SayHelloAgain(service_pb2.HelloRequest(name='you1'))
  18.           print("Greeter client received: " + response.message)
  19.  
  20.  
  21. if __name__ == '__main__':
  22.     logging.basicConfig()
  23.     run()
  24.  
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.
Aug 4 '23 #1
0 3956

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
7
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...
0
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...
14
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...
2
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...
0
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...
4
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...
4
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.