Matvey Tarasov
Matvey Tarasov

Reputation: 55

СGI python3 403 error

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?

Upvotes: 2

Views: 7728

Answers (1)

bhansa
bhansa

Reputation: 7504

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

Upvotes: 2

Related Questions