本文介绍了RPYC SSH连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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时出现以下错误

我认为这与密钥文件和证书文件有关,但我不确定如何设置它们。有什么主意吗?谢谢!

推荐答案

GAIERRORGETADDREADINFOE错误

此错误发生在名称解析失败的时候。

如果两台计算机都是Linux,则在/etc/hosts文件中添加条目或将"myserver"替换为IP地址。

这篇关于RPYC SSH连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 14:29