im learning the course : python for every body, and dr-chuck uses this code to receive data from outside the python :
import socket
my_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
my_socket.connect((‘data.pr4e.org’,80))
cmd=‘GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n’.encode()
my_socket.send(cmd)
while True:
data=my_socket.recv(512)
if len(data)<1:
break
print(data.decode())
my_socket.close()
But i only get a bunch of sad html ! like this :
400 Bad RequestBad Request
Your browser sent a request that this server could not understand.
Apache/2.4.18 (Ubuntu) Server at do1.dr-chuck.com Port 80