【问题标题】:Python not able to connect to grpc channel -> "failed to connect to all addresses" "grpc_status":14Python 无法连接到 grpc 通道->“无法连接到所有地址”“grpc_status”:14
【发布时间】:2019-12-27 04:31:53
【问题描述】:

我在尝试调用存根方法时收到以下错误。 知道是什么原因造成的吗?

[bolt.api.handlers] 2019-08-21 20:07:57,792 ERROR handlers:1066: 'ResourceHandler' object has no attribute 'ontology_service_handler'
Traceback (most recent call last):
  File "/bolt-webserver/bolt/api/onse/onse_handlers/ontology_service.py", line 17, in post
    ontology_id = await self.onse_stub.createOntology()
  File "/bolt-webserver/bolt/api/onse/onse_stub.py", line 41, in createOntology
    return self.stub.CreateOntology(ontology_messages_pb2.Ontology())
  File "/usr/local/lib/python3.6/site-packages/grpc/_channel.py", line 565, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/lib/python3.6/site-packages/grpc/_channel.py", line 467, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "failed to connect to all addresses"
        debug_error_string = "{"created":"@1566418077.791002345","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3818,"referenced_errors":[{"created":"@1566418077.790965749","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":395,"grpc_status":14}]}"

我尝试提供 IP 地址而不是主机名,但仍然出现相同的错误。 OnseStub 类在调用 createOntology 方法之前被初始化。 该服务已启动并正在运行。 失败的呼叫是从龙卷风网络应用程序完成的(以防万一)

class OnseStub:

    def __init__(self, ontology_service_backend):
    self.channel = grpc.insecure_channel('localhost:51051')
    self.stub = ontology_service_pb2_grpc.OntologyServiceStub(self.channel)

    def __del__(self):
    if self.channel != None:
    self.channel.close() # close grpc channel

    async def createOntology(self):
    return self.stub.CreateOntology(ontology_messages_pb2.Ontology())

【问题讨论】:

    标签: python grpc grpc-python


    【解决方案1】:

    这是常见的错误,它可能发生在不同的情况下。但在最常见的情况下,描述 https://github.com/grpc/grpc/issues/9987 可以通过取消设置 http_proxy 环境变量来修复

    if os.environ.get('https_proxy'):
     del os.environ['https_proxy']
    if os.environ.get('http_proxy'):
     del os.environ['http_proxy']
    

    【讨论】:

      【解决方案2】:

      为我解决的问题是将以下选项添加到客户端频道。

      grpc.insecure_channel('localhost:50051', options=(('grpc.enable_http_proxy', 0),))
      

      这在 grpc 快速入门中也没有,并且没有真正突出显示。

      【讨论】:

      • 您需要正确配置您的 CA 以信任 grpc 服务器证书,而不是强制不安全的连接
      猜你喜欢
      • 2021-12-06
      • 2020-05-06
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 2021-04-08
      • 2021-07-19
      • 2019-06-12
      • 1970-01-01
      相关资源
      最近更新 更多