Python cgi 奇怪的行为

发布于 2024-12-07 00:32:59 字数 303 浏览 0 评论 0原文

我有一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌入人心 2024-12-14 00:32:59

表示服务器上出现问题。 CGI 脚本中出现此错误的最常见原因是 CGI 脚本本身存在未捕获的错误,导致其过早终止。最好的办法是检查 Apache 错误日志。这些通常位于 /var/log//error.log (这可能是 /var/log/apache2/error.log 或 /var/log/httpd/ error.log 等)

既然您已经说过这在 shell 中运行良好,我的猜测是这是 sys.path 的问题(请记住,Apache 是不同的用户,它会有不同的设置),但我需要看到更多确定。

其他问题可能是:

  • 不同的 Python 版本(3 与 2)
  • 文件具有错误的权限(我相信 755 是标准)
  • Python 中某个与环境相关的语法错误

<!-- 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:

  • Different Python version (3 vs. 2)
  • File has the wrong permissions (755 is the standard, I believe)
  • Syntax error somewhere in Python which is environmentally dependant
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文