使用python连接到Go中运行的grpc服务的问题

时间:2018-06-14 23:09:55

标签: python grpc

我在使用python库连接到GO中运行的grpc服务时遇到问题

我正在使用图书馆

grpcio==1.10.1

这是我的代码

import grpc
from hello_world import hello_world_pb2_grpc
from hello_world import hello_world_pb2
channel = grpc.insecure_channel('localhost:5000')
stub =hello_world_pb2_grpc.CallStub(channel)
stub.Call()

我在执行

时设置调试模式后出现以下错误
channel = grpc.insecure_channel('localhost:5000')


>>> E0614 21:11:00.273830440   14198 channel_connectivity.cc:126] watch_completion_error: "Cancelled"
E0614 21:11:00.273870160   14198 completion_queue.cc:634]    Operation failed: tag=0x7fbaab82b320, error={"created":"@1529010660.273816994","description":"Timed out waiting for connection state change","file":"src/core/ext/filters/client_channel/channel_connectivity.cc","file_line":133}
E0614 21:11:00.474877364   14195 channel_connectivity.cc:126] watch_completion_error: "Cancelled"
E0614 21:11:00.474967852   14195 completion_queue.cc:634]    Operation failed: tag=0x7fbaab82b358, error={"created":"@1529010660.474849365","description":"Timed out waiting for connection state change","file":"src/core/ext/filters/client_channel/channel_connectivity.cc","file_line":133}
E0614 21:11:00.675819616   14198 channel_connectivity.cc:126] watch_completion_error: "Cancelled"
E0614 21:11:00.675860536   14198 completion_queue.cc:634]    Operation failed: tag=0x7fbaab82b358, error={"created":"@1529010660.675806653","description":"Timed out waiting for connection state change","file":"src/core/ext/filters/client_channel/channel_connectivity.cc","file_line":133}

E0614 21:11:00.876819325   14195 channel_connectivity.cc:126] watch_completion_error: "Cancelled"
E0614 21:11:00.876855700   14195 completion_queue.cc:634]    Operation failed: tag=0x7fbaab82b320, error={"created":"@1529010660.876806994","description":"Timed out waiting for connection state change","file":"src/core/ext/filters/client_channel/channel_connectivity.cc","file_line":133}

这就是错误的样子

E0614 19:43:39.385612320    8409 lockfree_event.cc:209]      LockfreeEvent::SetReady: 0x7f7b18001a28 curr=0x7f7b14001120
E0614 19:43:39.385634661    8409 lockfree_event.cc:209]      LockfreeEvent::SetReady: 0x7f7b18001a30 curr=0x2
E0614 19:43:39.385664271    8409 lockfree_event.cc:94]       LockfreeEvent::NotifyOn: 0x7f7b18001a28 curr=(nil) closure=0x7f7b14001120
E0614 19:43:39.390243947    8409 lockfree_event.cc:209]      LockfreeEvent::SetReady: 0x7f7b18001a28 curr=0x7f7b14001120
E0614 19:43:39.390261213    8409 lockfree_event.cc:209]      LockfreeEvent::SetReady: 0x7f7b18001a30 curr=0x2
E0614 19:43:39.390363730    8409 lockfree_event.cc:160]      LockfreeEvent::SetShutdown: 0x7f7b18001a28 curr=(nil) err={"created":"@1529005419.390300526","description":"Delayed close due to in-progress write","file":"src/core/ext/transport/chttp2/transport/chttp2_transport.cc","file_line":589,"referenced_errors":[{"created":"@1529005419.390289956","description":"Endpoint read failed","file":"src/core/ext/transport/chttp2/transport/chttp2_transport.cc","file_line":2446,"occurred_during_write":0,"referenced_errors":[{"created":"@1529005419.390275545","description":"Socket closed","fd":7,"file":"src/core/lib/iomgr/tcp_posix.cc","file_line":423,"grpc_status":14,"target_address":"ipv4:127.0.0.1:8081"}]}]}
E0614 19:43:39.390380912    8409 lockfree_event.cc:160]      LockfreeEvent::SetShutdown: 0x7f7b18001a30 curr=0x2 err={"created":"@1529005419.390300526","description":"Delayed close due to in-progress write","file":"src/core/ext/transport/chttp2/transport/chttp2_transport.cc","file_line":589,"referenced_errors":[{"created":"@1529005419.390289956","description":"Endpoint read failed","file":"src/core/ext/transport/chttp2/transport/chttp2_transport.cc","file_line":2446,"occurred_during_write":0,"referenced_errors":[{"created":"@1529005419.390275545","description":"Socket closed","fd":7,"file":"src/core/lib/iomgr/tcp_posix.cc","file_line":423,"grpc_status":14,"target_address":"ipv4:127.0.0.1:8081"}]}]}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/me/lib/python3.6/site-packages/grpc/_channel.py", line 500, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/home/me/lib/python3.6/site-packages/grpc/_channel.py", line 434, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, Socket closed)>

显示它无法连接到给定端口的给定服务。但是,其他服务可以连接到给定端口,用其他语言编写。

此外,如果我执行telnet localhost:5000,则可以连接

任何想法可能是什么问题?

0 个答案:

没有答案