AttributeError module 'socket' has no attribute 'socket'

import socket

mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('', 80))
cmd = 'GET HTTP/1.0\r\n\r\n'.encode()

while True:
    data = mysock.recv(512)
    if len(data) < 1:



I just started learning python through Coursera. So far it’s good but with ‘socket’ I keep getting attribute error. Can anybody help me on this one?
What am i doing wrong?

Thank you for any reply.

Traceback (most recent call last):
File “C:\Users*********************************”, line 5, in
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
AttributeError: module ‘socket’ has no attribute ‘socket’

My first guess is that you named a file in the same directory, and you’re importing that module instead of the built-in one?

When you run a python script with python, it will add the local directory to the path, and look for modules there before it looks in the standard library. So it’s easy to mess up and mask a standard module with your own.

1 Like

Thank you so much! I had a file named After deleted that file, it worked!

1 Like