我正在尝试通过python进行Web开发......在rhel6上使用默认的apache ....但需要一些指导
我的HTML表单位于/ var / www / html目录中:
add_employee.html:
<html>
<head>
<title>Add Employee</title>
</head>
<body>
<h1>Fill Out This Form</h1>
<form action="../cgi-bin/process.cgi" method="POST">
First Name : <input type="text" name="f_name"><br/>
Last Name: <input type="text" name="l_name"><br/>
Employee ID: <input type="number" name="emp_id"><br/>
CTC : <input type="number" name="emp_ctc"><br/>
<input type="submit" value="Add Employee">
</form>
</body>
</html>
现在我试图通过后端的python脚本获取表单内容:
process.cgi:
#!/usr/bin/python2.6
import cgi
formData = cgi.FieldStorage()
firstName = formData.getvalue('f_name')
filename="abc.txt"
txtw = open(filename,'w')
txtw.write(firstName)
但是我在通过浏览器将值传递给文件abc.txt
时收到错误以下是Apache HTTP错误日志报告的错误: ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++ [Thu Nov 03 22:48:25 2016] [错误] [client :: 1] Traceback(最近一次调用最后一次):,referer:http:localhost / add_employee.html [Thu Nov 03 22:48:25 2016] [错误] [client :: 1]文件“/var/www/cgi-bin/process.cgi”,第11行,in,referer:http:localhost / add_employee.html
[Thu Nov 03 22:48:25 2016] [错误] [client :: 1],referer:http:localhost / add_employee.html
[Thu Nov 03 22:48:25 2016] [错误] [client :: 1] txtw = open(filename,'w'),referer:http:localhost / add_employee.html
[Thu Nov 03 22:48:25 2016] [error] [client :: 1] IOError,referer:http:localhost / add_employee.html
[Thu Nov 03 22:48:25 2016] [错误] [client :: 1] :, referer:http:localhost / add_employee.html
[Thu Nov 03 22:48:25 2016] [错误] [client :: 1] [Errno 13]权限被拒绝:'abc.txt',referer:http:localhost / add_employee.html
[Thu Nov 03 22:48:25 2016] [错误] [client :: 1],referer:http:localhost / add_employee.html
[Thu Nov 03 22:48:25 2016] [错误] [client :: 1]脚本标题过早结束:process.cgi,referer:http:localhost / add_employee.html ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++