mac 下python import总是报错

kobewang 发布于 2015/08/29 22:36
阅读 287
收藏 0

报错信息:

wangyujiadeMacBook-Pro:documents wangyujia$ python server.py

Traceback (most recent call last):

  File "server.py", line 23, in <module>

    getInfo()

  File "server.py", line 7, in getInfo

    sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

AttributeError: 'module' object has no attribute 'AF_INET'

wangyujiadeMacBook-Pro:documents wangyujia$ python server.py

Traceback (most recent call last):

  File "server.py", line 23, in <module>

    getInfo()

  File "server.py", line 7, in getInfo

    sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

AttributeError: 'module' object has no attribute 'AF_INET'

server.py 源码:

#!/usr/bin/env python

#-*-coding:utf-8-*-


import socket

def getInfo():

address=('127.0.0.1',8888)

sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

sock.bind(address)

sock.listen(5)

client,addr=sock.accept()

print 'connected with',addr

client.send(b'Hi I am server!')

ra=sock.recv(1024)

print ra

client.close()

sock.close()

#end def


if __name__=='__main__':

getInfo()

加载中
0
Altman
Altman
我只能怀疑你自己写了个文件叫socket.py了
0
junanhonglei
junanhonglei

引用来自“Altman”的评论

我只能怀疑你自己写了个文件叫socket.py了
应该是的,下次提问的时候记得代码用“插入程序和代码”,看着难受
0
PynixWang
PynixWang

有一个中招的。。。

返回顶部
顶部