cgi.FieldStorage and REDIRECT_REQUEST_METHOD
Austyn Bontrager
austynjay at yahoo.com
Tue Jul 27 20:38:30 EDT 2004
Should cgi.FieldStorage examine the environment variable
REDIRECT_REQUEST_METHOD before examining REQUEST_METHOD?
I'm running Apache, and write my CGI scripts in Python.
I have this in a /techdocs/.htaccess file:
ErrorDocument 401 /forms/registration.cgi
Require valid-user
The registration script contains a <form method="POST">, so it submits
back to itself.
So a typical conversation goes like this:
> GET /techdocs/usermanual.pdf HTTP/1.1
< HTTP/1.1 401 Unauthorized
(browser pops up login box and user types something in username field)
> GET /techdocs/usermanual.pdf HTTP/1.1
> Authorization: Basic YWFhYTo=
< HTTP/1.1 200 OK
< <html><body><form method="POST"> ... </form></body></html>
> POST /techdocs/usermanual.pdf HTTP/1.1
> Authorization: Basic YWFhYTo=
> Content-Type: application/x-www-form-urlencoded
> username=joe&email=joe at mailinator.com
< HTTP/1.1 200 OK
< <html><body>Thanks for registering. Log in as "joe" to
< <a href="">Download</a> the file.</body></html>
(user clicks on that Download link)
> GET /techdocs/usermanual.pdf HTTP/1.1
> Authorization: Basic YWFhYTo=
< HTTP/1.1 200 OK
< Content-type: application/x-pdf
< ...
So after the POST, in my script I'd expect env variable REQUEST_METHOD
to be "POST". However, REQUEST_METHOD is "GET", and
REDIRECT_REQUEST_METHOD is "POST", and cgi.FieldStorage can't find the
form values.
I'm working around it by putting at the top of my script:
RRM = "REDIRECT_REQUEST_METHOD"
if os.environ.get(RRM)
os.environ["REQUEST_METHOD"] = os.environ.get(RRM)
Any better ideas? Should this be added to the cgi module (I think it's
specific to Apache)? Should I ask this question somewhere else?
Thanks
Austyn
More information about the Python-list
mailing list