HTTP 501 (Unsupported method ('POST'))

Okay so basically what I want to make is a connection between the python server and roblox studio (on localhost)

I dunno if roblox is really the best thing to use localhost on, for now I just couldnt make it work
Pretty sure there are other ways on doing this, I appreciate any help!

python-code which I copy pasted
# Python 3 server example
from http.server import BaseHTTPRequestHandler, HTTPServer

hostName = "localhost"
serverPort = 8000

class MyServer(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response_only(200)
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()
        self.wfile.write(bytes("<html><head><title>https://pythonbasics.org</title></head>", "utf-8"))
        self.wfile.write(bytes("<p>Request: %s</p>" % self.path, "utf-8"))
        self.wfile.write(bytes("<body>", "utf-8"))
        self.wfile.write(bytes("<p>This is an example web server.</p>", "utf-8"))
        self.wfile.write(bytes("</body></html>", "utf-8"))

if __name__ == "__main__":        
    webServer = HTTPServer((hostName, serverPort), MyServer)
    print("Server started http://%s:%s" % (hostName, serverPort))

    try:
        webServer.serve_forever()
    except KeyboardInterrupt:
        pass

    webServer.server_close()
    print("Server stopped.")

image

Command bar
image

Basic PostAsync
game:GetService("HttpService"):PostAsync("http://localhost:8000", "test")
1 Like

I can’t see a post handler in the python code, is there one?

Edit: I don’t think the server can access localhost:8000, you might have to give it your IP address and add the server port or smth

3 Likes

Your server only allows GET requests.

if you want it to handle POST requests, then change it to “do_POST”

1 Like

Ahhh this is literally so obvious, the keyword “post handler” made me realize that def do_GET is actually referring to the method itself :joy: :woozy_face:

Thanks for the help! I’ve added a post handler now!