Python cgi 奇怪的行为
我有一个带有 html 输出的简单 CGI python 脚本:
print "Content-Type: text/html"
print
print hours,minutes,seconds,","
当我从 Linux shell 运行它时,它运行良好,但是当从浏览器调用时,我得到的只是一个空白页面。以前当我使用 CRLF EOF 而不是 LF 时,我曾经遇到过这个问题,但我改变了它,并且它工作得很好,直到最近进行了一些修改。
我不知道当脚本从 shell 运行良好但从浏览器调用时不知道该怎么做。
I have a simple CGI python script with an html output:
print "Content-Type: text/html"
print
print hours,minutes,seconds,","
When I run it from my linux shell, it runs fine but when called from the browser, all I get is a blank page. I used to have this problem before when I used CRLF EOF instead of LF but I changed that and it worked fine until some recent modification.
I don't know what to do when the script runs fine from shell but not when called from a browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表示服务器上出现问题。 CGI 脚本中出现此错误的最常见原因是 CGI 脚本本身存在未捕获的错误,导致其过早终止。最好的办法是检查 Apache 错误日志。这些通常位于
/var/log//error.log
(这可能是 /var/log/apache2/error.log 或 /var/log/httpd/ error.log 等)既然您已经说过这在 shell 中运行良好,我的猜测是这是
sys.path
的问题(请记住,Apache 是不同的用户,它会有不同的设置),但我需要看到更多确定。其他问题可能是:
<!-- SHTML Wrapper - 500 Server Error -->
means that something is going wrong on the server. The most common cause in CGI scripts for this error is that there is an uncaught error in the CGI script itself, causing it to prematurely terminate. Your best bet is to check your Apache error logs. These will normally be in/var/log/<name of Apache install>/error.log
(This could be /var/log/apache2/error.log or /var/log/httpd/error.log, etc.)Since you've said that this works well in the shell, my guess is that this is an issue with
sys.path
(remember, Apache is a different user, it will have different settings), but I would need to see more to be certain.Other issues could be: