When I execute this script, I always get a Bad Request output. I don't understand what is going wrong. I wanted to print the output of my cmd variable and I see a b' as the prefix. I think this is how it is going to the server as a request and as a result it's failing. It's Python 3.7.0, by the way.
My code snippet is as follows:
import socket
brows = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
brows.connect(('data.pr4e.org', 80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n'.encode()
print(cmd)
brows.send(cmd)
while True:
data = brows.recv(512)
if (len(data) < 1):
break
print(data.decode())
brows.close()
My output is as follows:
I'm completely new to Python. Can someone please help me solve this?