[Tutor] 1.5.1 -> 1.5.2 cgi.Fieldstorage

Sean Conway seanconway@home.com
Mon, 30 Aug 1999 15:24:42 -0700


Hello everyone.

I am experimenting with Python + CGI, using Apache 1.3.6 and PyApache. I was
using Python 1.5.1 with no problems. However, when I tried to upgrade to
Python 1.5.2, the script below stopped working. Reverting back to 1.5.1 made
the error go away. Here is the script that fails with 1.5.2, and the error
it generates:

---script---
import cgi, string
input = open('/home/httpd/cgi-bin/data', 'r').readlines()
form = cgi.FieldStorage()
print "Content-type:
text/html\n\n<HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY>"
print "You voted for option: ", form["PRstats"].value, "<P>Current
votes:<P>"
x = string.atoi(form["PRstats"].value)
input[x] = str(string.atoi(input[x]) + 1) + "\n"
print "Votes for option 0: ", input[0], "<p>Votes for option 1: ", input[1],
"<p>Votes for option 2: ", input[2], "<p>Votes for option 3: ", input[3]
open('/home/httpd/cgi-bin/data', 'w').writelines(input)
print "</BODY></HTML>"

---error---
Traceback (innermost last):
  File "/home/httpd/cgi-bin/test2.py", line 3, in ?
    form = cgi.FieldStorage()
  File "/usr/lib/python1.5/cgi.py", line 792, in __init__
    method = string.upper(environ['REQUEST_METHOD'])
TypeError: impossible<bad format char>, string

This is a simple voting script that is 1/2 finished.

What has changed in Python 1.5.2 with regards to cgi.FieldStorage()?

I suppose it is possible that the RPM I d/led of Python 1.5.2 is partly
corrupted, although I don't think that is very likely.

Thanks in advance,

Sean Conway

P.S. Thanks to everyone who helped me out with my previous problem.