我正在尝试使用RPyC在google上的2个VM实例之间建立一个客户机-服务器连接。我有以下代码:
服务器端:
import rpyc
class MyService(rpyc.Service):
def on_connect(self):
# code that runs when a connection is created
# (to init the serivce, if needed)
pass
def on_disconnect(self):
# code that runs when the connection has already closed
# (to finalize the service, if needed)
pass
def exposed_get_answer(self): # this is an exposed method
return 42
def get_question(self): # while this method is not exposed
return "what is the airspeed velocity of an unladen swallow?"
if __name__ == "__main__":
from rpyc.utils.server import ThreadedServer
from rpyc.utils.authenticators import SSLAuthenticator
authenticator = SSLAuthenticator("myserver.key", "myserver.cert")
server = ThreadedServer(MyService, port=12345, authenticator=authenticator)
server.start()客户端:
import rpyc
conn = rpyc.ssl_connect("myserver", port = 12345, keyfile=None,
certfile=None)
conn.execute("print ('world')")当我运行Client.py时,我会得到以下错误
socket.gaierror: Errno -3名称解析的临时失败
我认为这与keyfile和certfile有关,但我不知道如何设置它们。有什么想法吗?谢谢!
发布于 2018-03-12 17:03:54
GAIERROR:Get A Info Error
当名称解析失败时,会出现此错误。
如果两台机器都是Linux,则在/etc/hosts文件中添加条目,或者将"myserver“替换为IP地址。
发布于 2018-02-07 09:00:37
检查名称"myserver“是否可访问,否则将其替换为IP地址。
https://stackoverflow.com/questions/47877442
复制相似问题