Python没有将值写入文件

时间:2018-04-12 14:45:39

标签: python

我有以下html:

<html>
<body>
<p>Please enter domain to add to EDL.</p>
<form action="/cgi-bin/domain.py" method="post">
Domain:  <input type="text" name="domain"></br>

<input type="submit" value="Submit" />
</form>
</body>
</html>  

和Python代码:

#!/usr/bin/python

# Import modules for CGI handling
import cgi, cgitb

# Create instance of FieldStorage
form = cgi.FieldStorage()

# Get data from fields
domain2 = form.getvalue('domain')

with  open('/tmp/pa-allowed-credentials.txt', 'a') as f:
        f.write(domain2)


print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Hello - Second CGI Program</title>"
print "</head>"
print "<body>"
print "<h2>%s added to the list</h2>" % (domain2)
print "</body>"
print "</html>"

我遇到的问题是python脚本没有写出&#34; domain2&#34;进入文件。如果我通过&#34; python domain.py&#34;执行脚本它工作正常。

0 个答案:

没有答案