1

I am asking it because I write very simply app but IT DON'T WORK. I wrote this command in terminal in the /dir:

python3 -m http.server --cgi  

My script is in dir/cgi-bin/hp.py and that code:

#!/usr/bin/env python3
print"Content-type: text/html"
print()
print"<h1>Hello world!</h1>"

This I saw in window of browser:

Error response
Error code: 403
Message: CGI script is not executable ('/cgi-bin/hp.py').
Error code explanation: HTTPStatus.FORBIDDEN - Request forbidden -- authorization will not help."

How can I fix it?

bhansa
  • 7,282
  • 3
  • 30
  • 55
  • @bhansa It doesn't fix my error =( – Matvey Tarasov Sep 15 '17 at 14:13
  • Check this: https://stackoverflow.com/questions/30516414/how-to-run-cgi-hello-world-with-python-http-server – bhansa Sep 15 '17 at 14:23
  • @bhansa it dosen't helped me. Interesting, that if I am runing Flask server for developers then everything is good. And if I am runing "socets-server", then also everything is good. But CGI -server doesn't work. – Matvey Tarasov Sep 15 '17 at 15:38
  • Read about [howto-linux-bsd-listing-permissions-of-file](https://www.cyberciti.biz/faq/howto-linux-bsd-listing-permissions-of-file/) – stovfl Sep 15 '17 at 18:07

1 Answers1

1

Here are the following steps which I tried to reproduce the problem:

# app.py
print("Content-type: text/html")
print()
print("<h1>Hello world!</h1>")
  1. Created a file app.py in cgi-bin directory
  2. Used command to run http.server with cgi
    • python -m http.server --bind localhost --cgi 8000

I tried accessing the path "http:localhost/cgi-bin/" got Error 403

Now the resolving part, which is opening the link in browser.

I ran the command:

python -mwebbrowser http://localhost:8000/cgi-bin/app.py

After the while it gave me the result, and I was able to access the link for the step 2 also.

I hope that helps you.

Result:

Result screenshot

Community
  • 1
  • 1
bhansa
  • 7,282
  • 3
  • 30
  • 55
  • Conflict of user access because app.py was create with limited opportunities (as me =) but run python-server was started as standard-user and not root. I created file as root and started server as root and everything is ok – Matvey Tarasov Sep 17 '17 at 08:05