简体   繁体   English

CGI无法与内置Python 3.1 http.server一起使用

[英]CGI not working with built-in Python 3.1 http.server

I'm using http.server with the CGIHTTPRequestHandler on OS X 10.6 and the posix code path in run_cgi() does not appear to work properly. 我在OS X 10.6上将http.server与CGIHTTPRequestHandler一起使用,并且run_cgi()中的posix代码路径似乎无法正常工作。 I'm calling a located at /cgi-bin/test.py from a form submit. 我正在从表单提交处调用位于/cgi-bin/test.py的地址。

For the better part of this afternoon I was receiving the error 'OSError: [Errno 2] No such file or directory' at the os.execve() line 1058 but now they are 'OSError: [Errno 8] Exec format error'. 在今天下午的大部分时间里,我在os.execve()第1058行收到错误“ OSError:[Errno 2] No such file or directory”,但现在它们是“ OSError:[Errno 8] Exec format error”。 I've changed so much I'm not sure about the reason for the different error, but either way do_POST() isn't working for me. 我已经进行了很大的更改,我不确定导致该错误的原因,但是无论哪种方式do_POST()都不适合我。

$ ./demon-local.py
Serving HTTP on 0.0.0.0 port 8000
localhost - - [27/Oct/2010 21:24:39] "POST /cgi-bin/test.py HTTP/1.1" 200 -
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/http/server.py", line 1058, in run_cgi
    os.execve(scriptfile, args, os.environ)
OSError: [Errno 8] Exec format error
localhost - - [27/Oct/2010 21:24:39] CGI script exit status 0x7f00

I've run the code in pdb and can't find anything wrong with the variables scriptfile, args, and os.environ. 我已经在pdb中运行了代码,但是变量scriptfile,args和os.environ找不到任何错误。 Once I reach the os.execve line in the debugger execution seems to just hang and I have to ctrl-c a few times to kill everything. 一旦我到达调试器中的os.execve行,执行似乎就挂起了,我必须按ctrl-c几次才能杀死所有内容。

Has anyone here had success using the built-in CGIHTTPRequestHandler? 这里有没有人使用内置的CGIHTTPRequestHandler成功?

Many thanks, Chris 非常感谢克里斯

Why would you write a CGI script in Python and then use a Python web server to do the CGI call!? 为什么要用Python编写CGI脚本,然后使用Python Web服务器进行CGI调用! Talk about forcing a camel through the eye of a needle. 谈论迫使骆驼穿过针眼。

Call the Python methods directly from Python instead. 而是直接从Python调用Python方法。 With Python 3.2 there should even be a reference WSGI implementation. 对于Python 3.2,甚至应该有一个参考WSGI实现。 Or you can look at the bottle framework, it supports Python 3. 或者,您可以看一下Bottle框架,它支持Python 3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM