在练习Python,socket库的时候,
发现connect在编译的时候,发生如下错误:
File "/usr/lib/Python2.7/socket.py", line 228, in meth return getattr(self._sock,name)(*args)
socket.gaierror: [Errno -2] Name or service not knownconnect里面写的是tuple,没问题
然后在Terminal里面,进行ping操作的时候,
啊哦……
ping: www.baidu.com: Name or service not known
ping IP试试
# ping 61.135.169.125
connect: Network is unreachable
OK
问题找到了,网络问题
ifconfig 发现eth0网卡,没有IP地址……
OK,Linux网络配置
# vi /etc/network/interfaces
参照最后两行,添加:
auto eth0
iface eth0 inet dhcp
重启网络
# /etc/init.d/networking restart
或者 # service network restart
再回来Py看看,正常了。。。。
本文记录了在使用Python的socket库时遇到的连接错误及其解决过程。通过排查网络配置和重启网络服务,最终解决了连接失败的问题。
3810

被折叠的 条评论
为什么被折叠?



