When I execute this code I get the following error:
import socket
s=socket.socket()
s.connect(("data.pr4e.org",80))
cmd='GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n'.encode()
s.send(cmd)
while True:
data=s.recv(512)
if (len(data)<1):
break
print(data.decode())
s.close()
Error:
Traceback (most recent call last):
File "socket.py", line 1, in <module>
import socket
File "/home/arnav/WorkSpace/Python/Coursera/AccessWebData/socket.py", line 2, in <module>
s=socket.socket()
TypeError: 'module' object is not callable
When this code is entered on the terminal, it works just fine.
I do not understand what I am doing wrong.
from socket import socketsince he is doings=socket.socket()instead ofs=socket(). Also i wouldnt consider this a duplicate since he added much more context than the original question.