Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python客户端GRPC与AWS的不安全连接问题_Python_Amazon Web Services_Grpc_Python 3.7 - Fatal编程技术网

Python客户端GRPC与AWS的不安全连接问题

Python客户端GRPC与AWS的不安全连接问题,python,amazon-web-services,grpc,python-3.7,Python,Amazon Web Services,Grpc,Python 3.7,我面临GRPC和python客户端的问题 以下是我所拥有的: import grpc import base64 from grpc_requests import StubClient from client_pb2_grpc import ClientServiceStub import client_pb2 import os # Client snippet server_port = 443 server_host = 'AWS host' # create channel in

我面临GRPC和python客户端的问题

以下是我所拥有的:

import grpc
import base64
from grpc_requests import StubClient
from client_pb2_grpc import ClientServiceStub
import client_pb2
import os


# Client snippet
server_port = 443
server_host = 'AWS host'

# create channel insecure
channel = grpc.insecure_channel('{}:{}'.format(server_host, server_port))
stub = ClientServiceStub(channel)


print("----------------------------------------------------------")

feature = stub.GetClientByCode(client_pb2.GetClientRequest(code="mycode"))
我一直得到的是:

I0420 12:57:40.628000000 26428 src/core/ext/filters/client_channel/client_channel.cc:1776] chand=000001A9014C0718: update: state=CONNECTING status=(OK) picker=000001A901545230
I0420 12:57:40.648000000 26428 src/core/ext/filters/client_channel/client_channel.cc:3177] chand=000001A9014C0718 calld=000001A9016014B0: creating dynamic call stack on channel_stack=000001A9015458D0
I0420 12:57:40.653000000 26428 src/core/ext/filters/client_channel/client_channel.cc:1183] chand=000001A9014C0718 dymamic_termination_calld=000001A901601800: create retrying_call=000001A901601860
I0420 12:57:40.656000000 26428 src/core/ext/filters/client_channel/client_channel.cc:4796] chand=000001A9014C0718 retrying_call=000001A901601860: create lb_call=000001A901A74FE0
I0420 12:57:40.659000000 26428 src/core/ext/filters/client_channel/client_channel.cc:5399] chand=000001A9014C0718 lb_call=000001A901A74FE0: LB pick returned QUEUE (subchannel=0000000000000000, error="No Error")
I0420 12:57:40.663000000 26428 src/core/ext/filters/client_channel/client_channel.cc:5323] chand=000001A9014C0718 lb_call=000001A901A74FE0: adding to queued picks list
I0420 12:57:40.701000000 26428 src/core/ext/filters/client_channel/client_channel.cc:2927] chand=000001A9014C0718 calld=000001A9016014B0: cancelling resolver queued pick: error="No Error" self=000001A9015E8F20 calld->resolver_pick_canceller=0000000000000000

I0420 12:57:41.139000000 26084 src/core/lib/surface/call.cc:586] grpc_call_unref(c=000001A901600B20)
I0420 12:57:41.141000000 26084 src/core/lib/surface/completion_queue.cc:1420] grpc_completion_queue_shutdown(cq=000001A97EF2F4C0)
I0420 12:57:41.144000000 26084 src/core/lib/surface/completion_queue.cc:1426] grpc_completion_queue_destroy(cq=000001A97EF2F4C0)
I0420 12:57:41.146000000 26084 src/core/lib/surface/completion_queue.cc:1420] grpc_completion_queue_shutdown(cq=000001A97EF2F4C0)
Traceback (most recent call last):
  File ".\grpc_test.py", line 29, in <module>
    feature = stub.GetClientByCode(client_pb2.GetClientRequest(code="mycode"))
  File "C:\Users\Programs\Python\Python37\lib\site-packages\grpc\_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\grpc\_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "failed to connect to all addresses"
        debug_error_string = "{"created":"@1618916261.039000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":5420,"referenced_errors":[{"created":"@1618916261.000000000","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":398,"grpc_status":14}]}"
>
I0420 12:57:40.6280000026428 src/core/ext/filters/client_channel/client_channel.cc:1776]chand=000001A9014C0718:update:state=CONNECTING status=(OK)picker=000001A901545230
I0420 12:57:40.6480000026428 src/core/ext/filters/client_channel/client_channel.cc:3177]chand=000001A9014C0718 calld=000001A9016014B0:在channel_stack=000001A9015458D0上创建动态调用堆栈
I0420 12:57:40.653000000 26428 src/core/ext/filters/client_channel/client_channel.cc:1183]chand=000001A9014C0718动态_终止_calld=000001A901601800:创建重试_call=000001A901601860
I0420 12:57:40.656000000 26428 src/core/ext/filters/client_channel/client_channel.cc:4796]chand=000001A9014C0718重试_call=000001A901601860:创建lb_call=000001A901A74FE0
I0420 12:57:40.659000000 26428 src/core/ext/filters/client_channel/client_channel.cc:5399]chand=000001A9014C0718 lb_call=000001A901A74FE0:lb pick返回队列(子通道=0000000000000000,错误=“无错误”)
I0420 12:57:40.663000000 26428 src/core/ext/filters/client_channel/client_channel.cc:5323]chand=000001A9014C0718 lb_call=000001A901A74FE0:添加到排队拣货列表
I0420 12:57:40.701000000 26428 src/core/ext/filters/client_channel/client_channel.cc:2927]chand=000001A9014C0718 calld=000001A9016014B0:取消冲突解决程序排队拾取:error=“No error”self=000001A9015E8F20 calld->冲突解决程序拾取\u canceller=0000000000000000
I0420 12:57:41.13900000026084 src/core/lib/surface/call.cc:586]grpc_call_unref(c=000001A901600B20)
I0420 12:57:41.141000000 26084 src/core/lib/surface/completion_queue.cc:1420]grpc_completion_queue_shutdown(cq=000001A97EF2F4C0)
I0420 12:57:41.144000000 26084 src/core/lib/surface/completion_queue.cc:1426]grpc_completion_queue_destroy(cq=000001A97EF2F4C0)
I0420 12:57:41.14600026084 src/core/lib/surface/completion_queue.cc:1420]grpc_completion_queue_shutdown(cq=000001A97EF2F4C0)
回溯(最近一次呼叫最后一次):
文件“\grpc_test.py”,第29行,在
feature=stub.GetClientByCode(client_pb2.GetClientRequest(code=“mycode”))
文件“C:\Users\Programs\Python\Python37\lib\site packages\grpc\\ u channel.py”,第946行,在调用中__
返回\u结束\u一元\u响应\u阻塞(状态、调用、错误、无)
文件“C:\Users\AppData\Local\Programs\Python\37\lib\site packages\grpc\\ u channel.py”,第849行,在一元响应中
raise\u InactiveRpcError(状态)
grpc.\u信道。\u不活动覆盖PCERROR:
你有什么提示吗?我读到,大多数面临同样问题的人通常都与港口有关。我在grpcurl中尝试了同样的指令,添加了一个权限(但在python中,我发现这个stuf有一些问题…)


提前感谢。

您可能需要发布跟踪日志的其他部分。要调试此问题,我们需要:

  • 检查名称解析是否有效,应该有一个日志,说明给定地址已解析为ip:port
  • 看看为什么每个地址都不工作,比如ip:端口不可访问

如果问题仍然无法解决,我建议将问题发布到。

最终成功。后期解决方案:

import grpc
import base64
from grpc_requests import StubClient
from client_pb2_grpc import ClientServiceStub
import client_pb2
import os

server_port = 'port'
server_host = 'host'
ca_cert = '.pem'
auth = 'auth'
with open(ca_cert, 'rb') as f:
    trusted_certs = f.read()

credentials = grpc.ssl_channel_credentials(root_certificates=trusted_certs)
# make sure that all headers are in lowecase, otherwise grpc throws an exception
call_credentials = grpc.metadata_call_credentials(
    lambda context, callback: callback(((('Authorization', 'Bearer'), auth),), None))

#call_credentials = grpc.access_token_call_credentials("test_access_token")
composite_credentials = grpc.composite_channel_credentials(credentials, call_credentials)
channel = grpc.secure_channel('{}:{}'.format(server_host, server_port), composite_credentials)
stub = ClientServiceStub(channel)

response = stub.GetClientByCode(client_pb2.GetClientRequest(code="local"))

print("[~] Greeter client received: {}".format(response.message))
此外,我需要在我的计算机中安装服务器证书,以确保安全连接