Python 成功部署到云运行后无法命中grpc服务器
类似的情况,但是,在我的案例中描述的解决方案不起作用。我想在google cloud run上运行grpc服务器,并能够调用它。我有一个基本的python grpc服务器,工作正常,在本地主机上使用Python 成功部署到云运行后无法命中grpc服务器,python,google-cloud-platform,grpc,google-cloud-run,Python,Google Cloud Platform,Grpc,Google Cloud Run,类似的情况,但是,在我的案例中描述的解决方案不起作用。我想在google cloud run上运行grpc服务器,并能够调用它。我有一个基本的python grpc服务器,工作正常,在本地主机上使用docker run运行gcr.io映像时,我的客户端可以调用它。但是,在成功部署到google cloud run之后,服务器在端口8080上侦听(我记录了它),我无法再使用客户端代码访问服务器 我收到以下消息: grpc._channel._InactiveRpcError: <_Inact
docker run
运行gcr.io
映像时,我的客户端可以调用它。但是,在成功部署到google cloud run之后,服务器在端口8080上侦听(我记录了它),我无法再使用客户端代码访问服务器
我收到以下消息:
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "DNS resolution failed"
debug_error_string = "{"created":"@1591245267.073965000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3981,"referenced_errors":[{"created":"@1591245267.073946000","description":"Resolver transient failure","file":"src/core/ext/filters/client_channel/resolving_lb_policy.cc","file_line":214,"referenced_errors":[{"created":"@1591245267.073945000","description":"DNS resolution failed","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc","file_line":357,"grpc_status":14,"referenced_errors":[{"created":"@1591245267.073882000","description":"C-ares status is not ARES_SUCCESS: Domain name not found","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc","file_line":244,"referenced_errors":[{"created":"@1591245267.059636000","description":"C-ares status is not ARES_SUCCESS: Domain name not found","file":"src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc","file_line":244}]}]}]}]}"
>
我的客户端代码,我两个都试过了
channel = grpc.insecure_channel('<the .run.app url on my cloud run service>:8080')
stub = my_service_pb2_grpc.MyServiceStub(channel)
request = my_service_pb2.MyEndpointRequest(
test='hello'
)
response = stub.MyEndpoint(request)
print(response)
channel=grpc.unsecure_channel(':8080')
存根=my_service_pb2_grpc.MyServiceStub(频道)
request=my\u service\u pb2.MyEndpointRequest(
测试class='hello'
)
response=stub.MyEndpoint(请求)
打印(答复)
及
使用grpc.secure_通道(':8080',grpc.ssl_通道_凭据())作为通道:
存根=my_service_pb2_grpc.MyServiceStub(频道)
request=my\u service\u pb2.MyEndpointRequest(
测试class='hello'
)
response=stub.MyEndpoint(请求)
打印(答复)
这两个都不起作用,给我的错误与我上面写的相同
此外,当我在命令行上执行ping
时,我会得到名称或服务未知
任何帮助都将不胜感激 设法解决了这个问题,解决方案是从云运行服务上显示的url中删除
https://
前缀,并使用443
端口而不是8080
with grpc.secure_channel(
'<url without https:// prefix>:443',
grpc.ssl_channel_credentials(),
) as channel:
stub = my_service_pb2_grpc.MyServiceStub(channel)
request = my_service_pb2.MyEndpointRequest(
test='hello'
)
response = stub.MyEndpoint(request)
print(response)
与grpc.secure\u通道(
':443',
grpc.ssl\u通道\u凭据(),
)作为频道:
存根=my_service_pb2_grpc.MyServiceStub(频道)
request=my\u service\u pb2.MyEndpointRequest(
测试class='hello'
)
response=stub.MyEndpoint(请求)
打印(答复)
设法解决了这个问题,解决方案是从云运行服务上显示的url中删除https://
前缀,并使用443
端口而不是8080
with grpc.secure_channel(
'<url without https:// prefix>:443',
grpc.ssl_channel_credentials(),
) as channel:
stub = my_service_pb2_grpc.MyServiceStub(channel)
request = my_service_pb2.MyEndpointRequest(
test='hello'
)
response = stub.MyEndpoint(request)
print(response)
与grpc.secure\u通道(
':443',
grpc.ssl\u通道\u凭据(),
)作为频道:
存根=my_service_pb2_grpc.MyServiceStub(频道)
request=my\u service\u pb2.MyEndpointRequest(
测试class='hello'
)
response=stub.MyEndpoint(请求)
打印(答复)
with grpc.secure_channel(
'<url without https:// prefix>:443',
grpc.ssl_channel_credentials(),
) as channel:
stub = my_service_pb2_grpc.MyServiceStub(channel)
request = my_service_pb2.MyEndpointRequest(
test='hello'
)
response = stub.MyEndpoint(request)
print(response)