Can't POST with python's http.server (code 501 Can only POST to CGI scripts)

63 Views Asked by At

Here is the python code I use to launch a server (when in the directory D:my-app/ where I have my html and javascript files) :

import http.server
server = http.server.HTTPServer
handler = http.server.CGIHTTPRequestHandler
handler.cgi_directories =["D:my-app/cgi-bin"]
PORT = 8080
server_address = ("", PORT)
httpd = server(server_address, handler)
httpd.serve_forever()

My javascript file (with jquery) contains the following code : $.post( "/cgi-bin/modify_file.php", {x_y: mousePosText.textContent,R: Math.min(0.85*h/2,0.85*w/2)} );

D:my-app/cgi-bin/ contains modify_file.php

I thought the following part would allow using the POST method with modify_file.php:

handler = http.server.CGIHTTPRequestHandler
handler.cgi_directories =["D:my-app/cgi-bin"]

Still, I get the error code 501 Can only POST to CGI scripts (which I think is typically due to not having set handler.cgi_directories).

Do you have any ideas on the problem ?

Note : My OS is Windows

Thanks all !

0

There are 0 best solutions below