Skip to content
Advertisement

How to send HTTP response (not request)?

I need to send an HTTP response like the one below using python. How can this be accomplished?

HTTP/1.1 200 OK

Advertisement

Answer

# set up socket and connection (socket library)
while True:
    sock, addr = servSock.accept()
    sock.send("""HTTP/1.1 200 OK
Content-Type: text/html

<html><body>Hello World</body></html>
""");
    sock.close()
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement