python socket connect错误

在练习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 known


connect里面写的是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学习)