I'm new to socket programming, and I basically wrote some code using the socket library that was supposed to print metadata and the website content of my desired website - in my case Facebook, http port 80..
My code looks like this:
import socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(('facebook.com',80))
GET = 'GET http://www.facebook.com HTTP/1.0\r\n\r\n'.encode()
s.send(GET)
while True:
data = s.recv(512)
if len(data) < 1:
break
print(data.decode())
s.close()
The problem is,when I run the program, I get 'HTTP/1.1 502 Error with server connection' The other outputted metadata at the top looks something like this:
Proxy-Status: server_connection_error; e_isproxyerr= (and a bunch of incomprehensible letters and numbers I won't include here)
Connection: close
Content-Length: 2959
My main goal was to print metadata with no errors and the desired content of the website, but it doesn't seem to be working. It also gave me an html script, but it didn't give me what I was looking for, the printed text on the facebook.com page which says 'Connect with friends and the world around you on Facebook.'
What am I doing/approaching wrong?