[問題] CGI問題

看板Python作者 (TEAL)時間13年前 (2011/05/04 14:33), 編輯推噓3(304)
留言7則, 4人參與, 最新討論串1/1
最近開始實作把一些程式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

05/04 16:20, , 1F
test.html的權限有正確嗎?
05/04 16:20, 1F
test.html是創出來的 所以原本是沒有的...... 不過我不知道怎麼創出來後權限直接改755?

05/04 16:28, , 2F
是沒有權限開新檔案嗎?
05/04 16:28, 2F
我也在想是不是這個問題,但這要怎麼著手下去?

05/04 20:40, , 3F
你執行的權限不夠,要試的話把 test.html 目錄改777看看
05/04 20:40, 3F
!!!可以了!~原來要把目錄的執行權開啟

05/05 11:00, , 4F
出來的檔案是阿怕契擁有的嗎?
05/05 11:00, 4F
是的~ 不過現在的問題是~~要怎麼把我創出來的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)

05/05 19:20, , 5F
請參考os.umask ~
05/05 19:20, 5F

05/05 19:20, , 6F
自動導向應該要吐header("Location: test.html");吧
05/05 19:20, 6F

05/05 19:20, , 7F
阿..我寫成php的樣子了 總之就是吐header XD
05/05 19:20, 7F
文章代碼(AID): #1DmFDCeW (Python)