2

On my locat host , if i run simple print statement it works fine. but i want to use textblob for sentiment analysis. For this purpose, I am trying to run below code on my localhost but it's showing error.

Code:

#!C:\fname lname\AppData\Local\Programs\Python\Python37-32\python.exe
from textblob.classifiers import NaiveBayesClassifier
from textblob import TextBlob

train = [
    ('I love this sandwich.', 'pos'),
    ('This is an amazing place!', 'pos'),
    ('I feel very good about these beers.', 'pos'),
    ('This is my best work.', 'pos'),
    ("What an awesome view", 'pos'),
    ('I do not like this restaurant', 'neg'),
    ('I am tired of this stuff.', 'neg'),
    ("I can't deal with this", 'neg'),
    ('He is my sworn enemy!', 'neg'),
    ('My boss is horrible.', 'neg')
]
test = [
    ('The beer was good.', 'pos'),
    ('I do not enjoy my job', 'neg'),
    ("I ain't feeling dandy today.", 'neg'),
    ("I feel amazing!", 'pos'),
    ('Gary is a friend of mine.', 'pos'),
    ("I can't believe I'm doing this.", 'neg')
]

cl = NaiveBayesClassifier(train)

# Classify some text
print(cl.classify("Their burgers are amazing."))  # "pos"
print(cl.classify("I don't like their pizza."))   # "neg"

# Classify a TextBlob
blob = TextBlob("The beer was amazing. But the hangover was horrible. "
                "My boss was not pleased.", classifier=cl)
print(blob)
print(blob.classify())

for sentence in blob.sentences:
    print(sentence)
    print(sentence.classify())

# Compute accuracy
print("Accuracy: {0}".format(cl.accuracy(test)))

# Show 5 most informative features
cl.show_informative_features(5)

I feel problem is these statements. Not sure how to fix it. Not sure if i need to import any library and should place it location where script is placed.

 from textblob.classifiers import NaiveBayesClassifier
    from textblob import TextBlob

Error appeared as :

Server error!
The server encountered an internal error and was unable to complete your request.

Error message: 
End of script output before headers: nltk.py

If you think this is a server error, please contact the webmaster.

Error 500
localhost
Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.

7

MrRaghav
  • 335
  • 3
  • 11
  • Please provide the full error traceback, so that we know what error you are encountering. – snakecharmerb Aug 17 '18 at 05:05
  • I have updated my post with error description. Please see post description to get the error details. – user3196663 Aug 17 '18 at 07:03
  • What is your python version in the server? – Srikanth Bhandary Aug 17 '18 at 07:06
  • I am using local host. I am adding this line in the start of script as well which includes python version. #!C:\fname lname\AppData\Local\Programs\Python\Python37-32\python.exe – user3196663 Aug 17 '18 at 07:07
  • If you're running this as a cgi script, can you add `import cgitb;cgitb.enable()` immediately after the `#!C:...` line. This should [ensure that the error traceback is displayed in the browser](https://docs.python.org/3/library/cgitb.html#module-cgitb), and then you can add it to your question. – snakecharmerb Aug 17 '18 at 17:55

0 Answers0