Python 2.7 [Errno 113] 没有到主机的路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39063817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 2.7 [Errno 113] No route to host
提问by ThePraetor
I have 2 computers on the same LAN. The first PC has an ip address 192.168.178.30, the other PC has an ip address 192.168.178.26. 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).
我在同一个局域网上有两台电脑。第一台PC的IP地址为192.168.178.30,另一台PC的IP地址为192.168.178.26。Ping、traceroute、telnet、ssh,两台电脑之间一切正常。两台 PC 运行相同的操作系统 - CentOS 7 并且两台 PC 都具有相同的 python 版本 2.7.5(使用 python -V 命令检查)。
I copied simple python code from a computer networking book.
我从一本计算机网络书中复制了简单的 python 代码。
client.py
客户端.py
from socket import *
serverName = '192.168.178.30'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = raw_input('Input lowercase sentence: ')
clientSocket.send(sentence)
modifiedSentence = clientSocket.recv(1024)
print 'From Server:', modifiedSentence
clientSocket.close()
server.py
服务器.py
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind(('192.168.178.30',serverPort))
serverSocket.listen(5)
print 'The server is ready to receive'
while 1:
connectionSocket, addr = serverSocket.accept()
sentence = connectionSocket.recv(1024)
capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence)
connectionSocket.close()
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.
该代码在同一台 PC 上运行时有效(服务器正在侦听本地主机)。当我在一台 PC 上运行客户端代码并在另一台 PC 上运行服务器代码时,我在客户端收到此错误。
Traceback (most recent call last):
File "client.py", line 5, in <module>
clientSocket.connect((serverName,serverPort))
File "/usr/lib64/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 113] No route to host
Can someone help?
有人可以帮忙吗?
回答by Messa
Check the firewall (on the server).
检查防火墙(在服务器上)。
回答by DeepSpace
You should bind
the server socket to '0.0.0.0'
, not '192.168.178.30'
.
您应该bind
将服务器套接字改为'0.0.0.0'
,而不是'192.168.178.30'
。
回答by ThePraetor
I stopped the firewall like Messa suggested and now it works.
我像 Messa 建议的那样停止了防火墙,现在它可以工作了。
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).
我仍然不明白问题是什么。我什至尝试使用不同的发行版。是否所有发行版都有严格的防火墙之类的。例如 Ubuntu 到 Ubuntu,Ubuntu 到 CentOS,CentOS 到 Ubuntu 我仍然有同样的问题(错误)。
回答by Yort
~]#supervisord
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
你应该使用
ln -s /etc/supervisor/supervisord.conf /usr/etc/supervisord.conf