I am working thru some literature in an effort to learn python on my own. My efforts were progressing favorably until recently when the subject turned to sockets. I have little knowledge in networking but I need help in this area to continue on. The simple listing that I have copied from the book that I am working through looks like this. Also here is the error message:
---------------------------------------------------------------
b'HTTP/1.1 400 Bad Request\r\nDate: Thu, 14 Dec 2017 11:03:36 GMT\r\nServer: Apache/2.4.27 (Unix)\r\nContent-Length: 226\r\nConnection: close\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>400 Bad Request</title>\n</head><body>\n<h1>Bad Request</h1>\n<p>Your browser sent a request that this server could not understand.<br />\n</p>\n</body></html>\n'
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import socket mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mysock.connect(( "www.netbsd.org" , 80 )) mysock.send(b "GET / HTTP/1.0\n\n" ) res = mysock.recv( 1024 ) while res ! = b"": print (res) res = mysock.recv( 1024 ) |
b'HTTP/1.1 400 Bad Request\r\nDate: Thu, 14 Dec 2017 11:03:36 GMT\r\nServer: Apache/2.4.27 (Unix)\r\nContent-Length: 226\r\nConnection: close\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>400 Bad Request</title>\n</head><body>\n<h1>Bad Request</h1>\n<p>Your browser sent a request that this server could not understand.<br />\n</p>\n</body></html>\n'