python xmlrpc server Cannot receive any XMLRPC from other computers

Question:

I wrote this server using xmlrpc in python
I want to be albe to access this server from any computer but it throws error. And another thing is that how can I make sure that the my server can support more than 1 client at a time?

from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/RPC2',)

# Create server
with SimpleXMLRPCServer(('82.155.18.86', 8000),
                        requestHandler=RequestHandler) as server:
    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 'mul').
    class MyFuncs:
        def mul(self, x, y):
            return x * y

    server.register_instance(MyFuncs())

    # Run the server's main loop
    server.serve_forever()

and this is the client side which I want to run on another computer

import xmlrpc.client

s = xmlrpc.client.ServerProxy('http://82.155.18.86:8000')
print(s.pow(2,3))  # Returns 2**3 = 8
print(s.add(2,3))  # Returns 5
print(s.mul(5,2))  # Returns 5*2 = 10

# Print list of available methods
print(s.system.listMethods())

but this is what I get in response

C:UsersNimaPycharmProjectsRPCvenvScriptspython.exe C:/Users/Nima/PycharmProjects/RPC/main.py 
Traceback (most recent call last):
  File "C:UsersNimaPycharmProjectsRPCmain.py", line 4, in <module>
    print(s.pow(2,3))  # Returns 2**3 = 8
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libxmlrpcclient.py", line 1116, in __call__
    return self.__send(self.__name, args)
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libxmlrpcclient.py", line 1456, in __request
    response = self.__transport.request(
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libxmlrpcclient.py", line 1160, in request
    return self.single_request(host, handler, request_body, verbose)
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libxmlrpcclient.py", line 1172, in single_request
    http_conn = self.send_request(host, handler, request_body, verbose)
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libxmlrpcclient.py", line 1285, in send_request
    self.send_content(connection, request_body)
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libxmlrpcclient.py", line 1315, in send_content
    connection.endheaders(request_body)
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libhttpclient.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libhttpclient.py", line 1010, in _send_output
    self.send(msg)
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libhttpclient.py", line 950, in send
    self.connect()
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libhttpclient.py", line 921, in connect
    self.sock = self._create_connection(
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libsocket.py", line 843, in create_connection
    raise err
  File "C:UsersNimaAppDataLocalProgramsPythonPython39libsocket.py", line 831, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Process finished with exit code 1
Asked By: Nima

||

Answers:

Have a look onto the doc.

It seems you are confusing the ports. Server port is 8000, but client tries to connect on port 3000. That won’t match.

Also it is good practice to make use of with statements, like shown in the doc.

Answered By: woodz
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.