我试图从Python客户机调用运行在.Net核心项目上的GRPC服务器。在
当在localhost:5001
上运行时,它工作得很好,但是在同一个网络(如192.168.1.230:5001
)中运行机器的实际IP时,它不起作用,我得到一个错误DNS resolution failed
。在
我已经下载了SSL证书,目前正在从客户端以文件的形式读取它。它在运行localhost
时起作用,所以我不认为这是问题所在。在
有没有更好的方法来进行这种测试,让客户机运行在与服务器相同的网络上的不同设备上?在开发过程中把GRPC服务器托管在外面并不是最好的解决方案。在
Python代码:
import grpc
import datamessage_pb2 as datamessage
import datamessage_pb2_grpc as datamessageService
def main():
print("Calling grpc server")
with open("localhost.cer", "rb") as file:
cert = file.read()
credentials = grpc.ssl_channel_credentials(cert)
channel = grpc.secure_channel("https://192.168.1.230:5001", credentials)
# channel = grpc.secure_channel("localhost:5001", credentials)
stub = datamessageService.StationDataHandlerStub(channel)
request = datamessage.StationDataModel(
temperature=22.3, humidity=13.3, soilMoisture=35.0)
result = stub.RegisterNewStationData(request)
print(result)
main()
Program.cs
中的服务器设置:
回溯:
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "DNS resolution failed"
debug_error_string = "{"created":"@1576101634.549000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3934,"referenced_errors":[{"created":"@1576101634.549000000","description":"Resolver transient failure","file":"src/core/ext/filters/client_channel/resolving_lb_policy.cc","file_line":262,"referenced_errors":[{"created":"@1576101634.549000000","description":"DNS resolution failed","file":"src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc","file_line":202,"grpc_status":14,"referenced_errors":[{"created":"@1576101634.549000000","description":"OS Error","file":"src/core/lib/iomgr/resolve_address_windows.cc","file_line":96,"os_error":"No such host is known.\r\n","syscall":"getaddrinfo","wsa_error":11001}]}]}]}"
目前没有回答
相关问题 更多 >
编程相关推荐