作者elvisteal (TEAL)
看板Python
标题[问题] CGI问题
时间Wed May 4 14:33:44 2011
最近开始实作把一些程式webcgi化却发生了很大的一个问题
#!/usr/local/bin/python
#encoding:utf-8
import time,math,os,re,string,cgi,cgitb
form=cgi.FieldStorage()
accode = form.getvalue('accode')
pwd = form.getvalue('pwd')
filename = accode + ".html"
f=open(filename,"w+")
若不加f=open(filename,"w+") 则可以正常运作
一加後变成
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to
complete your request.
Please contact the server administrator,webmaster@localhost and inform them of
the time the error occurred,and any thing you might have done that may have caused the error.
More information about this error may be available in the server error log.
我看了一下error log
它上面写
Traceback (most recent call last):
File "usr/lib/cgi-bin/GetDataCgi.py", line 420, in <module>
main()
File "usr/lib/cgi-bin/GetDataCgi.py", line 391 in main
f=open(filename , "w+")
IOError: [Errno 13] Permission denied: 'test.html'
[error] [client 127.0.0.1] Premature end of script headers: GetDataCgi.py,
referer: http:127.0.0.1/menu.htm
[error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
但我的cgi执行权限有改成755啊...
还是我还有什麽需要改的?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.70.89.89
1F:→ purincess:test.html的权限有正确吗? 05/04 16:20
test.html是创出来的
所以原本是没有的......
不过我不知道怎麽创出来後权限直接改755?
2F:→ suzuke:是没有权限开新档案吗? 05/04 16:28
我也在想是不是这个问题,但这要怎麽着手下去?
3F:推 Ebergies:你执行的权限不够,要试的话把 test.html 目录改777看看 05/04 20:40
!!!可以了!~原来要把目录的执行权开启
4F:推 losehole:出来的档案是阿怕契拥有的吗? 05/05 11:00
是的~
不过现在的问题是~~要怎麽把我创出来的test.html自动改权限成755......
有办法在创建这档案时就自动设成权限755这样吗?!
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
最後我用subprocess处理掉了
但底下还没想到.....
还有另一个问题就是我要怎麽.py执行完後网页自动导向test.html啊?
※ 编辑: elvisteal 来自: 203.70.89.89 (05/05 15:43)
※ 编辑: elvisteal 来自: 203.70.89.89 (05/05 16:00)
5F:推 purincess:请参考os.umask ~ 05/05 19:20
6F:→ purincess:自动导向应该要吐header("Location: test.html");吧 05/05 19:20
7F:→ purincess:阿..我写成php的样子了 总之就是吐header XD 05/05 19:20