Reputation: 23
I was trying to run my webpage in localhost. I am using python http.server to run the code in localhost. It works for GET requests but not working for POST.
python -m http.server --cgi 8080
It is showing
"Error code: 501
Message: Can only POST to CGI scripts.
Error code explanation: HTTPStatus.NOT_IMPLEMENTED - Server does not support this operation."
Upvotes: 1
Views: 2198
Reputation: 9753
CGI scripts have to be in a special directory, like cgi-bin:
Only directory-based CGI are used
cgi_directories¶
This defaults to ['/cgi-bin', '/htbin'] and describes directories to treat as containing CGI scripts.
So you can use them this way:
In a terminal, run: python3 -m http.server --cgi 8080
and in another one:
$ cat cgi-bin/foo.py
#!/usr/bin/env python3
import sys
print('200 OK\r\n\r\nfoo')
$ chmod u+x cgi-bin/foo.py
$ curl http://localhost:8080/cgi-bin/foo.py -X POST
foo
Upvotes: 2