Python 2.7 [Errno 113]没有主机路由

问题描述 投票:3回答:4

我在同一个局域网上有2台计算机。第一台PC的IP地址为192.168.178.30,另一台PC的IP地址为192.168.178.26。 Ping,traceroute,telnet,ssh,两台PC之间的一切都可以正常工作。两台PC运行相同的操作系统 - CentOS 7,两台PC都具有相同的python版本2.7.5(使用python -V命令检查)。

我从计算机网络书中复制了简单的python代码。

client.朋友

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.朋友

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()

代码在同一台PC上运行时(服务器在localhost上监听)。当我在一台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

有人可以帮忙吗?

python python-2.7 sockets
4个回答
5
投票

检查防火墙(在服务器上)。


3
投票

你应该bind服务器插座'0.0.0.0',而不是'192.168.178.30'


1
投票

我像Messa建议的那样停止了防火墙,现在它可以工作了。

service firewalld stop

我仍然不明白问题是什么。我甚至尝试使用不同的发行版。所有发行版都有严格的防火墙或其他东西。例如Ubuntu到Ubuntu,Ubuntu到CentOS,CentOS到Ubuntu我仍然遇到同样的问题(错误)。


0
投票
~]#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

你应该使用ln -s /etc/supervisor/supervisord.conf /usr/etc/supervisord.conf

© www.soinside.com 2019 - 2024. All rights reserved.