cgi python
Christian Hausknecht
christian.hausknecht at tu-clausthal.de
Thu Oct 13 11:09:53 EDT 2005
Python_it wrote:
> I going to use the cgi-handler (mod_python):
>
> http://www.modpython.org/live/mod_python-3.2.2b/doc-html/hand-cgi.html
>
>
> If I test a simply py script it works
>
> code:
> ===========
> print "Content-type: text/html\n"
> print """
> <html>
> <body>
> <h1>TEST</h1>
> </body>
> </html>
> """
> ============
>
> But if I test a py script with cgi comments (import cgi):
>
> Part of the code
> ============
> import cgi
>
> #get HTTP query parameters
> query = cgi.FieldStorage()
>
> #Get the selected year and month
> selectedYear = int(query["year"].value)
> selectedMonth = int(query["x"].value) + 1
>
> #Get the monthly revenue
> monthlyRevenue = float(query["value"].value)
> ============
>
> I get the following error:
>
> errormessage:
> ==========================
> Mod_python error: "PythonHandler mod_python.cgihandler"
>
> Traceback (most recent call last):
>
> File "C:\Program
> Files\Python24\Lib\site-packages\mod_python\apache.py", line 299, in
> HandlerDispatch
> result = object(req)
>
> File "C:\Program
> Files\Python24\Lib\site-packages\mod_python\cgihandler.py", line 96, in
> handler
> imp.load_module(module_name, fd, path, desc)
>
> File "C:/Program Files/Apache
> Group/Apache2/htdocs/clue/modules/templates\clickpie.py", line 9, in ?
> selectedYear = int(query["year"].value)
>
> File "C:\Program Files\Python24\Lib\cgi.py", line 559, in __getitem__
> raise KeyError, key
>
> KeyError: 'year'
>
>
> Who can help me?
There is no Parameter 'year' in the Format-String sent by the Webserver!
You can test it like this:
if(query.has_key("yaer")):
xyz = query["year"].value
If you want to get a Parameter called 'year', you must call the cgi-Script
like this:
http://host/path-to-cgi-dir/script.py?year=2005
Another method is, to use a form in the calling html-Page and put a hidden
value into it.
Ciao,
Christian
More information about the Python-list
mailing list