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

试图在python程序一个套接字,属性错误每次我尝试使用套接字模块。属性应该在那里。我此时只是复制和粘贴教程代码和仍然给了我错误。 Traceback (most recent call last): File "C:\Users\micheal\workspace\GCNSocket\socket\GCNSocket.py", line 18, in except socket.error, msg: AttributeError: 'module' object has no attribute 'error'代码如下 import time import socket import sys host_ip="209.208.78.170" port=8099 if __name__ == "__main__": currentTime=time.time() #current time (time) lastTime=time.time() #records last time of last received packet (time) try: mySocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM) # create socket except socket.error, msg: print ('Failed to create socket. Error code: ' + str(msg) + ' , Error message : ' + msg) sys.exit() print("Starting Connection") if(mySocket.connect((host_ip,port))): #connect print("Connected to 209.208.78.170 port 8099") else: print("Unable to Connect")如果我删除try块创建套接字,我得到同样的错误与“套接字”
已邀请:

空心菜 - 牛逼你来

赞同来自: Ansible

你使用套接字作为包名称。它导致进口包套接字而不是标准库模块socket
重命名它所以它不冲突与标准库模块的名字。

要回复问题请先登录注册