#!/usr/bin/env python
import cgi, cgitb
cgitb.enable()
form = cgi.FieldStorage()
query = form.getvalue('question')
import nltk
from nltk import load_parser
cp=load_parser('grammars/book_grammars/myfile.fcfg')
trees = list(cp.parse(query.split("")))
answer = trees[0].label()['SEM']
answer = [s for s in answer if s]
q=' '.join(answer)
import MySQLdb
db=MySQLdb.connect(host="localhost",
user="root",
passwd="mysql",
db="nation")
cur=db.cursor()
cur.execute(q)
x=cur.fetchone()
y=x[0]
db.close()
print "Content-Type: text/plain;charset=utf-8"
print "Hello World!"
print "Answer : %s " % (y)
当我在ubuntu中使用AMPPS在localhost上执行它时,我收到错误 - >
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/usr/local/ampps/www/cgi-bin/database1.py in ()
cp=load_parser('grammars/book_grammars/myfile.fcfg')
trees = list(cp.parse(query.split("")))
answer = trees[0].label()['SEM']
answer = [s for s in answer if s]
trees undefined, builtin list = <type 'list'>, cp =<nltk.parse.featurechart.FeatureChartParser object>, cp.parse = <bound method FeatureChartParser.parse of
<nltk.parse.featurechart.FeatureChartParser object>>, query = None, query.split undefined
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'split'
args = ("'NoneType' object has no attribute 'split'",)
message = "'NoneType' object has no attribute 'split'"
这个问题的解决方案是什么?