CGI 无法与内置 Python 3.1 http.server 配合使用
我在 OS X 10.6 上将 http.server 与 CGIHTTPRequestHandler 一起使用,并且 run_cgi() 中的 posix 代码路径似乎无法正常工作。我正在从表单提交中调用位于 /cgi-bin/test.py 的位置。
今天下午的大部分时间里,我在 os.execve() 第 1058 行收到错误“OSError:[Errno 2]没有这样的文件或目录”,但现在它们是“OSError:[Errno 8] Exec格式错误”。我已经改变了很多,我不确定不同错误的原因,但无论哪种方式 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
我已经在 pdb 中运行了代码,但找不到变量 scriptfile、args 和 os.environ 的任何问题。一旦我到达调试器中的 os.execve 行,执行似乎就会挂起,我必须按 ctrl-c 几次才能杀死所有内容。
这里有人成功使用内置的 CGIHTTPRequestHandler 吗?
非常感谢, 克里斯
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. I'm calling a located at /cgi-bin/test.py from a form submit.
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'. 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.
$ ./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. 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.
Has anyone here had success using the built-in CGIHTTPRequestHandler?
Many thanks,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么要用 Python 编写 CGI 脚本,然后使用 Python Web 服务器来执行 CGI 调用!?谈论强迫骆驼穿过针眼。
而是直接从 Python 调用 Python 方法。对于 Python 3.2,甚至应该有一个参考 WSGI 实现。或者你可以看看bottle框架,它支持Python 3。
Why would you write a CGI script in Python and then use a Python web server to do the CGI call!? Talk about forcing a camel through the eye of a needle.
Call the Python methods directly from Python instead. With Python 3.2 there should even be a reference WSGI implementation. Or you can look at the bottle framework, it supports Python 3.