Python 2.7 [Errno 113] No route to host


I have 2 computers on the same LAN. The first PC has an ip address, the other PC has an ip address
Ping, traceroute, telnet, ssh, everything works between the two PCs. Both PCs run the same OS – CentOS 7 and both PCs have the same python version 2.7.5 (checked with the python -V command).

I copied simple python code from a computer networking book.

from socket import *
serverName = ''
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
sentence = raw_input('Input lowercase sentence: ')
modifiedSentence = clientSocket.recv(1024)
print 'From Server:', modifiedSentence

from socket import *
serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
print 'The server is ready to receive'
while 1:
       connectionSocket, addr = serverSocket.accept()
       sentence = connectionSocket.recv(1024)
       capitalizedSentence = sentence.upper()

The code works when it is ran on the same PC (where the server is listening on localhost).
When I run the client code on one PC and the server code on the other PC I get this error on the client side.

Traceback (most recent call last):
  File "", line 5, in <module>
  File "/usr/lib64/python2.7/", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 113] No route to host

Can someone help?

Asked By: ThePraetor



Check the firewall (on the server).

Answered By: Messa

I stopped the firewall like Messa suggested and now it works.

service firewalld stop

I still don’t understand what the problem was. I even tried using different distributions. Do all distributions have strict firewalls or something. For example Ubuntu to Ubuntu, Ubuntu to CentOS, CentOS to Ubuntu I still had the same problem (error).

Answered By: ThePraetor
Error: No config file found at default paths (/usr/etc/supervisord.conf, /usr/supervisord.conf, supervisord.conf, etc/supervisord.conf, /etc/supervisord.conf); use the -c option to specify a config file at a different path
For help, use /usr/bin/supervisord -h

You should use
ln -s /etc/supervisor/supervisord.conf /usr/etc/supervisord.conf

Answered By: Yort

None of this stuff worked for me. I just connected both the devices to the same WiFi network and my program worked!

Answered By: Pyzard

You can also get this same error ([Errno 113] No route to host) if you are trying to connect 2 devices on the same network. the error can be fixed by double checking to make sure both devices are connected to the mqtt_client or whatever you are using. as soon as I connected the device I was trying to talk to everything worked as to be expected.I would also check to make sure the right IP_Address is being passed

Answered By: Adam Rhoades

We had this problem. I am putting our findings here in case anyone else stumbles across this question like I did.

Our configuration:

  • Host A: IP address, netmask
  • Host B: IP address, netmask

Neither host has a default gateway.

We are connecting from Host B to Host A. (That is not a typo.) The connect call succeeds, but when we try to send data, we get errno 113 aka. EHOSTUNREACH aka. "No route to host".

The fix, of course, was to change the subnet on Host A to match Host B.

We were surprised to see this error on a connection within the same subnet / same LAN. And we were surprised that connect succeeded followed by send failing. And we were surprised to see this error on Host B even though the network configuration on Host B itself was fine.

Somehow, the incorrect subnet on Host A caused this error on Host B…

…and just like that, today I learned about ICMP "destination unreachable" messages.

Answered By: Nemo
service firewalld stop

This helped me. I turned them off on both devices to be safe.

Answered By: theBird
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.