Response with 200 - Code works on runs, not on host

I spent ages trying to get this to work. On my end I kept of getting:
curl: (52) Empty reply from server

But when I looked at others code, it was the same as mine. When I pushed it the test was successful. Just wondering why on my machine it doesn’t work but on the git runners it does. I am on a kali VMware machine.
Curl command I used curl -v 127.0.0.1:4221
Here is my code:

import socket  


def handle_response(conn):
    response = conn.recvmsg(1024)
    msg = "HTTP/1.1 200 OK\r\n\r\n"
    conn.send(msg.encode())

    


def main():
    server_socket = socket.create_server(("localhost", 4221))
    

    try:
        while True:
            conn, addr = server_socket.accept()

            handle_response(conn)


            conn.close()            
             


    except KeyboardInterrupt:
        print("\n Server is shutting down.")
    finally:
        # Clean up the server socket
        server_socket.close()
        print("Server has been shut down")

if __name__ == "__main__":
    main()

Okay, if I just run the code using Python script and it is works! Maybe it has something to do with the Python virtual environment being set up in the your_program.sh.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.