0
#!/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)

When I am executing it on localhost using AMPPS in ubuntu I am getting error->

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'"

What is the solution of this problem?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Shubham Tiwari
  • 392
  • 1
  • 2
  • 15

0 Answers0