Reputation: 21
I start python local server on ubuntu, server.py:
from http.server import HTTPServer, CGIHTTPRequestHandler
server_address = ("", 8000)
httpd = HTTPServer(server_address, CGIHTTPRequestHandler)
httpd.serve_forever()
it's start and open index.html:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Обработка данных форм</title>
</head>
<body>
<form action="/cgi-bin/form.py">
<input type="text" name="TEXT_1">
<input type="text" name="TEXT_2">
<input type="submit">
</form>
</body>
</html>
Then i send GET request i have 403 Code Error:
Error response
Error code: 403
Message: CGI script is not executable ('/cgi-bin/form.py').
Error code explanation: HTTPStatus.FORBIDDEN - Request forbidden -- authorization will not help.
form.py:
#!/usr/bin/env python3
import cgi
form = cgi.FieldStorage()
text1 = form.getfirst("TEXT_1", "не задано")
text2 = form.getfirst("TEXT_2", "не задано")
print("Content-type: text/html\n")
print("""<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Обработка данных форм</title>
</head>
<body>""")
print("<h1>Обработка данных форм!</h1>")
print("<p>TEXT_1: {}</p>".format(text1))
print("<p>TEXT_2: {}</p>".format(text2))
print("""</body>
</html>""")
I try on Win 10 and it works well.
I know about start server on Linyx like this:
python3 -m http.server --cgi
but i need start from file.
Upvotes: 1
Views: 496