openSsh client.py不工作,显示连接错误



我的配置文件:

Host server
User new_user
HostName 10.0.1.193
Port 55555
LocalForward 3000 10.0.1.193:6000
IdentityFile ~/.ssh/server

Client.py

import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost:3000')
print s.pow(2,3)  # Returns 2**3 = 8
print s.add(2,3)  # Returns 5
print s.div(5,2)  # Returns 5//2 = 2
# Print list of available methods
print s.system.listMethods()

Server.py

from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/RPC2',)
# Create server
server = SimpleXMLRPCServer(("localhost", 6000),
                            requestHandler=RequestHandler)
server.register_introspection_functions()
# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)
# Register a function under a different name
def adder_function(x,y):
    return x + y
server.register_function(adder_function, 'add')
# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
    def div(self, x, y):
        return x // y
server.register_instance(MyFuncs())
# Run the server's main loop
server.serve_forever()

我的server.py运行正常,但是当我运行client.py时,它给出了以下错误:

Traceback (most recent call last):
  File "client.py", line 4, in <module>
    print s.pow(2,3)  # Returns 2**3 = 8
  File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1292, in single_request
    self.send_content(h, request_body)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1439, in send_content
    connection.endheaders(request_body)
  File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 776, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 757, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
socket.error: [Errno 111] Connection refused

我已经检查了我的ssh是否工作,我可以ssh到远程服务器与给定的配置,即

ssh server

找工作。有人能解释一下哪里出了问题吗?

您的服务器运行,也许它没有抱怨,但这并不意味着它"正确运行",或者更确切地说,它并不意味着服务器处于客户端期望的工作状态。

上面的内容有点神秘,原因是:一些未知的东西出了问题,即使你还不知道是什么出了问题,你也想开始测试你知道应该工作的东西,并验证它们实际上是工作的。这是一个有用的调试技巧,即使错误对您来说毫无意义。

在这种情况下,客户端错误消息是"connection refused",意思是"refused [at the server]"。

试试这个:在终端/DOS窗口中的"客户端"PC上运行:Telnet[你的服务器ip][你的服务器端口]

你应该预料到同样的错误——连接被拒绝。也许服务器实际上并没有打开端口。或者,服务器打开了端口,但由于服务器上的防火墙,您无法在另一台主机上远程看到它。

同时,在同一主机上运行客户端和服务器代码有时可以揭示更多的线索(它应该工作,但如果它没有,那么可能有不止一个问题)。

最新更新