Code:

import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('172.0.0.1', 1234)) 

In this case, an error 111

Connection refused

With what it can be connected? Or how can I analyze the error to fix it?

  • 2
    probably no one is listening on port 1234. or firewall does not pass (but this is unlikely) - Mike

2 answers 2

In general, the correct answer is really that no one is listening at the port.

But it is not listening, most likely due to the fact that the IP address is incorrect - it should be 127.0.0.1 for localhost (unlike 172.0.0.1 in your example)

In such cases, it makes sense to try to connect with third-party utilities (such as telnet) to check what the problem is - in python or in the port.

 atlant@NewFarm:/$ telnet localhost 8888 Trying 127.0.0.1... Connected to localhost. Escape character is '^ 
  • it can be noted that, unlike 172.16.0.1 (rfc 1918) , 172.0.0.1 not a private address and therefore probably belongs to an external server. - jfs

Nobody is listening on the port. Therefore, there is nothing to connect.

  • Please try to write more detailed answers. Now nothing is clear. - Nicolas Chabanovsky