【问题标题】:Setting up python in sourceforge在 sourceforge 中设置 python
【发布时间】:2013-01-12 14:52:08
【问题描述】:

我正在尝试在我的 sourceforge 存储库中托管示例程序 test.py。我从目录/home/project-web/motiur/cgi-bin/ 上传了我的文件,然后转到motiur.sourceforge.net/cgi-bin/test.py。不幸的是,我收到一个错误,提示标题过早结束。

test.py的源码:

#!/usr/local/bin/python
import cgi, cgitb
print "Content-type:text/html\n"
print "<html><body>This is another test</body></html>"

确切的错误是:

An error has been encountered in accessing this page. 
  1. Server: motiur.sourceforge.net 
  2. URL path: /cgi-bin/test.py 
  3. Error notes: Premature end of script headers: test.py 
  4. Error type: 500 
  5. Request method: GET 
  6. Request query string: 
  7. Time: 2013-01-12 14:49:39 UTC (1358002179)

顺便说一句,我在windows中使用filezilla并将文件权限设置为755,即每个人都可以执行该文件。这是一个菜鸟问题,将不胜感激。谢谢。

【问题讨论】:

  • @YannisRizos:错误是;访问此页面时遇到错误。 1. 服务器:motiur.sourceforge.net 2. URL 路径:/cgi-bin/test.py 3. 错误说明:脚本头提前结束:test.py 4. 错误类型:500 5. 请求方法:GET 6.请求查询字符串:7。时间:2013-01-12 14:49:39 UTC (1358002179)
  • @YannisRizos:有什么建议吗?
  • 看文章Premature end of script headers。我注意到不同的一件事是它们在 print "Content-type:text/html\n\n" 的末尾有一个额外的换行符。
  • @martineau:对不起,问题仍然存在,即使在您更改之后。

标签: python cgi sourceforge


【解决方案1】:

试试这个:

print 'Content-type: text/html'
print ''
print '<html><body>This is another test</body></html>'

您可能需要在响应正文前添加两个 '\n\n'。

编辑

然后试试这个:

#!/usr/bin/env python

在顶部而不是

#!/usr/local/bin/python

【讨论】:

  • 抱歉错误仍然存​​在。代码行有没有问题:#!/usr/local/bin/python import cgi, cgitb。顺便说一句,我的代码在我的 localhost 中运行得很好。我怀疑 python 解释器的链接和我的 test.py 文件的访问链接。
  • 对不起,我仍然收到premature end of script headers 错误。您可以访问motiur.sourceforge.net/cgi-bin/test.py 的站点以查看错误。
  • sourceforge 使用 python 3 吗?如果是这样,您需要在字符串周围加上括号。
  • 不,它使用python 2.4.3;很奇怪!
  • 然后我会尝试在其他地方部署。 2.4.3太古老了,没有人能合理地支持它。应该有人为此向 SourceForge 大喊大叫。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-22
相关资源
最近更新 更多