【问题标题】:FileNotFoundError: [Errno 2] CGI, python3FileNotFoundError:[Errno 2] CGI,python3
【发布时间】:2019-08-06 06:50:02
【问题描述】:

我一直在寻找解决方案,但没有一个能帮助我。

关键点:

操作系统:Ubuntu 18.04
要运行的文件:/var/www/html/cgi_test/cgi-bin/hello.py(肯定存在)
其中python3:/usr/bin/python3(操作系统默认)
文件夹 cgi_test 中文件/目录的权限:

drwxrwxr-x 1 cgi-bin
-rwxrwxrwx 1 cgi-bin/hello.py

/var/www/html/cgi_test/cgi-bin/hello.py的内容:

#!/usr/bin/python3
import cgi
import cgitb; cgitb.enable()
print("Content-Type: text/plain\r\n\r\n")
print('hi')

在文件夹 cgi_test 中运行命令:python3 -m http.server --cgi --bind 192.168.50.4 8000 在浏览器中访问http://192.168.50.4:8000/cgi-bin/hello.py时出现错误/响应:

Serving HTTP on 192.168.50.4 port 8000 (http://192.168.50.4:8000/) ...
192.168.50.1 - - [15/Mar/2019 08:14:26] "GET /cgi-bin/hello.py HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('192.168.50.1', 52548)
Traceback (most recent call last):
  File "/usr/lib/python3.6/http/server.py", line 1126, in run_cgi
    os.execve(scriptfile, args, env)
FileNotFoundError: [Errno 2] No such file or directory: '/var/www/html/cgi_test/cgi-bin/hello.py'
----------------------------------------
192.168.50.1 - - [15/Mar/2019 08:14:26] CGI script exit status 0x7f00

浏览器中的空白页面。

没有更多的想法来完成这项工作。

【问题讨论】:

  • @Justice_Lords 谢谢,我用 vi 写了文件,那里没有奇怪的字符

标签: python python-3.x cgi simplehttpserver


【解决方案1】:

可能有点晚了,但我有一个类似的问题,我通过在 cgi (.py) 脚本的第一行中使用正确的 python 版本来解决这个问题。例如。 #!/usr/bin/python3.7

【讨论】:

    猜你喜欢
    • 2014-11-13
    • 1970-01-01
    • 2021-03-25
    • 2019-09-20
    • 2020-11-08
    • 2020-09-15
    • 1970-01-01
    • 2019-10-26
    • 1970-01-01
    相关资源
    最近更新 更多