Empty output for NLTK function in CGI script

I want to use python NLTK library’s function in CGI script to tokenize some text, recieved via WEB.

If i simply use:

someamountoftext = "someamountoftext someamountoftext someamountoftext"

and then




It will work.

BUT! If I use this:

import os
import urllib.parse
import nltk
query_dict = urllib.parse.parse_qs(os.environ['QUERY_STRING'])

def tknz_wrd(someamountoftext):

print("Content-Type: text/html\n")

print (tknz_wrd(someamountoftext))

(Above is all my code of sigle file, no frameworks or something).

It does not print anything on screen. No erros, just white browser screen. Ofcourse, I tried manual input like:


It did not change anything.

morgot.py - name of my CGI file.

Where is my mistake? And\or how to make tokenization via WEB?

I use: Apache/2.4.53 (Win64) OpenSSL/1.1.1n PHP/7.4.28

python 3.10.4

Problem solved. So i made few mistakes, and the correct code is:


import os
import urllib.parse
import nltk

query_dict = urllib.parse.parse_qs(os.environ[‘QUERY_STRING’])
input_something = str(query_dict[‘someamountoftext’])[2: -2]
def tknz_wrd(someamountoftext):

print(“Content-Type: text/html\n”)

print (tknz_wrd(input_something))

It processes data, recieved from browser line, like: http://localhost/speciallocation/local/tokenize/morgot.py?someamountoftext=Enter%20your%20text%20here

morgot.py - name of CGI file.

‘?someamountoftext=’ This is how you enter data into variable

%20 - spacebar in browser line.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.