Connectionrefusederror: [Errno 111] XML-RPC python

Asked

Viewed 240 times

1

I’m trying to connect to a server using python 3 with xml-rpc, but an error is appearing every time I try to connect: Connectionrefusederror: [Errno 111] Connection refused

This is my server code: (NOTE: I’m just running silly tests.)

from xmlrpc.server import SimpleXMLRPCServer

def void():
  x = 1000
  i = 0
  while i < x:
      i = i+1
  return True

def main():
  print("This is a server!")
  server = SimpleXMLRPCServer(("localhost", 8080))
  server.register_function(void)
  server.serve_forever()

if __name__ == "__main__":
  main()

That’s my client code:

import xmlrpc.client
import time

def main():
  print("This is a client!")
  client = xmlrpc.client.ServerProxy("http://localhost:8000")
  client.void()

if __name__ == "__main__":
  start = time.time()
  main()
  total_time = ("--- %s seconds ---" % (time.time() - start))
  print("Time: " + str(total_time))

When I run xml-rpc on the same computer (different terminal) it works normal, but when I try on two different computers, it gives this error.

  • Juny, as the name suggests (Stackoverflow in Portuguese), the official language used here is Portuguese. So could you please translate your question? If you prefer, you can also ask the same question on Stackoverflow website in English.

  • Wow, I totally confused hahaha. I already translated, thanks for the feedback!

  • 1

    Have you tried instead of http://localhost you put the IP of the computer on the local network ? Ex: http://192.168.0.30:8000 ?

  • Yeeeeah! It worked! Thanks @Noobsaibot

  • @Noobsaibot better put the comment as an answer so that others who have the same problem find the solution by google (:

1 answer

2


You are getting the error:

Connectionrefusederror: [Errno 111] Connection refused

because it is trying to access a Loopback interface, the loopback interface is a virtual network interface used basically for two purposes:

  • Diagnosis;
  • For developing and testing systems that require a network interface with an IP (Webservers, etc).

To access on your local network, you need to locate your server’s local IP address by doing a survey on Google, you find several tutorials teaching you how to find the address. But by default, routers and or mold use 192.168.0.x or 192.168.1.x.

References

Browser other questions tagged

You are not signed in. Login or sign up in order to post.