I am trying to make a python web server with the Socket module. I am following this video https://www.youtube.com/watch?v=_najJkyK46g.
This is my code:
import socket
host = ''
port = 8000
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind((host, port))
listen_socket.listen(1)
print("Listening on port "+str(port))
while True:
client_connection, client_address = listen_socket.accept()
request = client_connection.recv(1024)
print(request)
http_response = "Hello World."
client_connection.sendall(bytes(http_response.encode('utf-8')))
client_connection.close()
When I go to chrome and enter 127.0.0.1:8000 it doesn't work. It brings up an error saying "This page isn't working". 127.0.0.1 sent an invalid response. ERR_INVALID_HTTP_RESPONSE. Please help me?