2012-03-12 100 views
2

我似乎无法打开,写从我的CGI脚本的文本文件。我不断收到权限错误(这是我从CGITb看到)Python的CGI权限错误

每当我试着这样做:

f = open("/Users/varatis/Documents/data.txt","a+") 

我得到这个:

<type 'exceptions.IOError'>: [Errno 13] Permission denied: '/Users/varatis/Documents/data.txt' 
    args = (13, 'Permission denied') 
    errno = 13 
    filename = '/Users/varatis/Documents/data.txt' 
    message = '' 
    strerror = 'Permission denied' 

理想情况下,我要创建的文本文件。但是,为了使事情服务器更容易,我试着让事情通过使预制的data.txt容易,运行常用的:

chmod a+x data.txt 
chmod a+w data.txt 
chown 70 data.txt  (70 is the uid the server runs on, obtained by os.getuid from the os module) 

然而,这些甚至不似乎工作。有没有人有这方面的经验,可以帮助我?同样,理想情况下,我将追加到来自CGI脚本的文本文件,并在不存在的情况下创建它。

而且,也许使用的将是香格里拉的data.txt中的LS:

[email protected] 1 _www staff 0 Mar 12 16:18 data.txt 

回答

0

很可能你的网络服务器没有权限写入到该指定的目录。 如果它是一个Apache,那么你可能想要摆弄'Directory'指令。

更新: Documents目录的权限是什么?

+0

HTTPd指令只影响HTTPd。 CGI脚本是独立的进程。 – 2012-03-12 21:17:57

+0

好点Ignacio - 谢谢 – 2012-03-13 21:25:36