QUERY_STRING error

Doug Stanfield DOUGS at oceanic.com
Sun Oct 29 12:48:53 EST 2000


Some guessing here and some advice. 

> Traceback (innermost last):
>   File "./viestit.cgi", line 5, in ?
>     komento = environ["QUERY_STRING"]
>   File "/opt/python/lib/python1.5/UserDict.py", line 12, in 
> __getitem__
>     def __getitem__(self, key): return self.data[key]
> KeyError: QUERY_STRING

I assume from this that this is a cgi program that you are trying to
troubleshoot.  I also assume that when you are getting this traceback you
have tried to run it from the command line.  The environment variable
QUERY_STRING is not there when you run this way.  It is something that is
set up by the web server before the server launches your requested cgi
script.  Therefore, if you want to test a cgi script without the server you
need to figure out how to set up that variable first.

> #!/opt/python/bin/python  
> 
> from string import *
> from os import environ

You should probably stop using this form of import in production scripts
(assuming you want this one to be production).  Its not a lot more typing to
do 'import string' and then use string.split().

> q = environ["QUERY_STRING"]
> 
> tiedosto = open("msg.txt","r").read()
> rivit = splitfields(tiedosto,"<!--msg-->")

Splitfields has been depracated and is now spelled split.  Is this an old
script you've inherited?
 
> print "Content-type: text/html\n\n";
> 
> print """<html>
> <head>
> <META HTTP-EQUIV=\"Expires\" CONTENT=\"Mon, 06 Jan 1990 
> 00:00:01 GMT\">
> <meta http-equiv=\"refresh\" content=\"100\">
> <title>viestit</title>
> <base target=\"_top\">
> </head>
> <body topmargin=\"0\">"""
> 
> if q == "fullscreen":
>     print "<a href=\"http://www.host.xxx/~viirua/chat/\"
> target=\"_top\">Palauta normaali näkymä.</a><br><br>"
> else:
>     print "<a href=\"viestit.cgi?fullscreen\" target=\"_top\">Avaa
> viestit kokoru utuun.</a><br><br>"
> 
> 
> for luku in range(1,50):
>     print rivit[luku]
> 
> print """<br>
> <br></body>
> </html>""" 
> 
> </snip>
> 
Although I haven't used it yet, I'd suggest you look at:

http://webware.sourceforge.net/

As part of this effort there is something called CGI Wrapper that might make
your development easier.

-Doug-




More information about the Python-list mailing list