I am using below code to print data from this URL http://data.pr4e.org/romeo.txt
I have tried this code on windows 10.1 system. Is there any modification that I need to escape the (400 Bad Request) result in cmd.
#Code
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('data.pr4e.org',80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\r\n\r\n'.encode()
mysock.send(cmd)
while True:
data = mysock.recv(512)
if len(data) < 1:
break
print(data.decode())
mysock.close()
Output :
C:\Users\Taufique\Desktop\p4e>python socket1.py HTTP/1.1 400 Bad Request Date: Mon, 13 Jul 2020 15:08:08 GMT Server: Apache/2.4.18 (Ubuntu) Content-Length: 308 Connection: close Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at do1.dr-chuck.com Port 80</address>
</body></html>