gpt4 book ai didi

python - СGI python3 403错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:45:50 26 4
gpt4 key购买 nike

我问这个问题是因为我编写了非常简单的应用程序,但它不起作用。我在 /dir 的终端中编写了此命令:

python3 -m http.server --cgi  

我的脚本位于 dir/cgi-bin/hp.py 中,该代码:

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

这是我在浏览器窗口中看到的:

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."

如何修复它?

最佳答案

以下是我尝试重现该问题的以下步骤:

# app.py
print("Content-type: text/html")
print()
print("<h1>Hello world!</h1>")
  1. cgi-bin目录中创建了一个文件app.py
  2. 使用命令通过 cgi 运行 http.server
    • python -m http.server --bind localhost --cgi 8000

我尝试访问路径“http:localhost/cgi-bin/”得到错误403

现在是解析部分,即在浏览器中打开链接。

我运行了命令:

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

过了一会儿,它给了我结果,我也能够访问第 2 步的链接。

希望对您有帮助。

结果:

Result screenshot

关于python - СGI python3 403错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46241041/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com