我之前有一个python脚本,如果在命令行或终端上执行它会起作用,现在我正在尝试使用cgi-bin运行浏览器,但是我的脚本不能正常运行?
HTML
<html><body>
<form enctype="multipart/form-data" action="http://10.88.25.48/cgi-bin/coba5.py" method="post">
File: <input type="file" name="file"><br/>
<input type="submit" value="Upload"><br/>
</form>
</body></html>
Python cgi
#!/usr/bin/python
import cgi, os
import cgitb; cgitb.enable()
import simplejson as json
import optparse
import sys
form = cgi.FieldStorage()
# A nested FieldStorage instance holds the file
fileitem = form['file']
fn = os.path.basename(fileitem.filename)
data = open('/tmp/upload-cgi/' + fn, 'wb').write(fileitem.file.read())
location_database = open('/home/bioinformatics2/DW/taxo.json', 'r')
database = json.load(location_database)
for line in data:
for taxonomy in database:
if taxonomy["genus"] == line.replace('\n','') :
print "Kingdom: %s," % taxonomy['kingdom'],
print "phylum: %s," % taxonomy['phylum'],
print "class: %s," % taxonomy['class'],
print "order: %s," % taxonomy['order'],
print "family: %s," % taxonomy['family'],
print "genus: %s" % taxonomy['genus']
break
else:
print ("No found genus on taxanomy")
print """\
Content-Type: text/html\n
<html><body>
<p>%s</p>
</body></html>
""" % (message,)