Reputation: 31
Trying to program a socket in python but keep getting attribute errors every time I try to use the socket module. The attributes should be there. They are rather basic things. I have at this point just copy and pasted tutorial code and still it gives me error.
Traceback (most recent call last):
File "C:\Users\micheal\workspace\GCNSocket\socket\GCNSocket.py", line 18, in <module>
except socket.error, msg:
AttributeError: 'module' object has no attribute 'error'
and my code is
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[0]) + ' , Error message : ' + msg[1])
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")
If I remove the try block and just create the socket, I get same error with 'socket' instead of 'error'
Upvotes: 1
Views: 3963
Reputation: 369134
You're using socket
as a package name. It cause import of your package socket
instead of standard library module socket
.
Rename it so it does not collide with standard library module name.
Upvotes: 2