[英]Python socket.error: [Errno 113] No route to host but ping works
I am trying to connect using TCP. 我正在尝试使用TCP进行连接。 In the client side I have the following code
在客户端,我有以下代码
import socket
BUFFER_SIZE = 1024
server_addres = ('172.16.1.52',3201)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(server_addres)
data = s.recv(BUFFER_SIZE)
s.close()
print "received data:", data
I run it using: 我使用以下命令运行它:
sudo python myProgram.py
This error appears 出现此错误
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 113] No route to host
However if i run: 但是,如果我运行:
sudo ping 172.16.1.52
The pings work properly. ping正常工作。 I need to run ping as sudo because running it without sudo gives
ping: icmp open socket: Operation not permitted
我需要以sudo的身份运行ping,因为在没有sudo的情况下运行ping会导致
ping: icmp open socket: Operation not permitted
It ended up being a routing policy of a radio interface. 最终成为无线电接口的路由策略。 It didn't allow TCP packets.
它不允许TCP数据包。 The rule was set by the IT deparment and could not be changed.
该规则是由IT部门设置的,无法更改。
I reached this conclusion after sendind TCP packets to other hosts using another interface (ie my code worked) 在使用另一个接口将sendcp TCP数据包发送到其他主机后,我得出了这个结论(即,我的代码有效)
I made sure there was a route. 我确保有一条路线。 I manually set the routing table for the specific IP and made sure the input policy from the remote host was set to accept TCP packets.
我手动设置了特定IP的路由表,并确保将来自远程主机的输入策略设置为接受TCP数据包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.