SimpleXMLRPCServer:无法建立连接,因为目标计算机主动拒绝它

时间:2018-05-14 18:04:39

标签: python connection simplexmlrpcserver

我正在尝试在VM中创建一个xmlrpc服务器,如果我将主机作为 localhost ,然后当我尝试通过客户端连接时发生错误。

E:\Programming\Python\xmlserver>python xml_client.py
Traceback (most recent call last):
  File "xml_client.py", line 6, in <module>
    print s.system.listMethods()
  File "C:\Python27\lib\xmlrpclib.py", line 1240, in __call__
    return self.__send(self.__name, args)
  File "C:\Python27\lib\xmlrpclib.py", line 1599, in __request
    verbose=self.__verbose
  File "C:\Python27\lib\xmlrpclib.py", line 1280, in request
    return self.single_request(host, handler, request_body, verbose)
  File "C:\Python27\lib\xmlrpclib.py", line 1308, in single_request
    self.send_content(h, request_body)
  File "C:\Python27\lib\xmlrpclib.py", line 1456, in send_content
    connection.endheaders(request_body)
  File "C:\Python27\lib\httplib.py", line 1049, in endheaders
    self._send_output(message_body)
  File "C:\Python27\lib\httplib.py", line 893, in _send_output
    self.send(msg)
  File "C:\Python27\lib\httplib.py", line 855, in send
    self.connect()
  File "C:\Python27\lib\httplib.py", line 832, in connect
    self.timeout, self.source_address)
  File "C:\Python27\lib\socket.py", line 575, in create_connection
    raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it

但是当我设置 VM IP 而不是localhost时,它完全正常。我需要在多台机器上运行xmlserver。那么对于每台机器,我是否必须提供机器的IP而不是仅仅在服务器文件中提供 localhost ?并使用机器IP连接到此服务器。

以下是我的示例服务器文件

from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler

def ping():
    return True

server = SimpleXMLRPCServer(('localhost', 9000))
server.register_function(ping)

if __name__ == '__main__':
    server.serve_forever()

0 个答案:

没有答案