473,836 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cgi.FieldStorag e and REDIRECT_REQUES T_METHOD

Should cgi.FieldStorag e examine the environment variable
REDIRECT_REQUES T_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.cg i
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><fo rm method="POST"> ... </form></body></html>
POST /techdocs/usermanual.pdf HTTP/1.1
Authorization: Basic YWFhYTo=
Content-Type: application/x-www-form-urlencoded
us************* *******@mailina tor.com
< HTTP/1.1 200 OK
< <html><body>Tha nks for registering. Log in as "joe" to
< <a href="">Downloa d</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_REQUES T_METHOD is "POST", and cgi.FieldStorag e can't find the
form values.

I'm working around it by putting at the top of my script:
RRM = "REDIRECT_REQUE ST_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
Jul 18 '05 #1
1 1829
On 2004-07-28, Austyn Bontrager <au*******@yaho o.com> wrote:
Should cgi.FieldStorag e examine the environment variable
REDIRECT_REQUES T_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.cg i
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><fo rm method="POST"> ... </form></body></html>
POST /techdocs/usermanual.pdf HTTP/1.1
Authorization: Basic YWFhYTo=
Content-Type: application/x-www-form-urlencoded
us************* *******@mailina tor.com


< HTTP/1.1 200 OK
< <html><body>Tha nks for registering. Log in as "joe" to
< <a href="">Downloa d</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_REQUES T_METHOD is "POST", and cgi.FieldStorag e can't find the
form values.

I'm working around it by putting at the top of my script:
RRM = "REDIRECT_REQUE ST_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?

You might try here:
http://python.org/sigs/web-sig/
http://mail.python.org/mailman/listinfo/web-sig

or if you are pretty sure this is an apache only thing try:
http://httpd.apache.org/lists.html

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1253
by: Fred Murray | last post by:
Hi all, When uploading a file ("input type=file"), FieldStorage usually behaves correctly, but every once in a while (every couple days?), it will suddenly start causing internal server errors. A look at the apache (v. 2.0.44 on Linux) error log shows "premature end of script headers" with no error messages from Python. After reloading the browser about 10 times in a row, it will suddenly start working again. Recently, when a series...
1
1640
by: Ames Andreas (MPA/DF) | last post by:
Hi, sorry for following-up to myself. Some remarks: 1) Please excuse the bogus original message. I wrote it a minute before I knocked off work and I promise to never do so again :-) 2) What I really wanted to know was: FieldStorage writes what it reads from the stream that is given to its constructor's fp (or sys.stdin by default) to a temporary file only _in some cases_. My
1
1953
by: Ames Andreas (MPA/DF) | last post by:
Hi, I'm currently using Zope 2.7.2-0 which in turn uses cgi.FieldStorage from Python 2.3.4. FieldStorage can either build a 'list' or a 'file' to represent a request. Unfortunately it overwrites __len__ such that it throws an exception when the request wasn't of type 'multipart', i.e. when it doesn't 'return' a list but a file. I'd consider this a bug because if you have an instance fs of FieldStorage you can't safely write
4
2123
by: Derek Basch | last post by:
Given this FieldStorage object: FieldStorage(None, None, ) I am trying to cgi.urlencode the FieldStorage object to POST to another cgi script. The documentation for urlencode, http://docs.python.org/lib/module-urllib.html , says that urlencode takes a mapping object or a list of double tuples. I see that I could use cgi.parse_qs and cgi.parse_qsl to create these object types. Should I just use that or should I continue using...
3
2214
by: Chris Curvey | last post by:
I can't be the first person to want to do this, but I also can't seem to find a solution. (Perhaps my Google skills are poor today.) How can I emulate cgi.FieldStorage() for my unit tests so that I don't have to put a web server in the way? what I'd like to do is something like fs = cgi.FieldStorage() fs = "bar" functionToBeTested(fs)
0
1902
by: John Salerno | last post by:
I'm trying to use a for loop with a FieldStorage object and I get the following error. Can you not treat it like a dictionary, or am I writing the for loop incorrectly? for item in form: print item # or print item.value
7
1590
by: John Salerno | last post by:
If I want to get all the values that are entered into an HTML form and write them to a file, is there some way to handle them all at the same time, or must FieldStorage be indexed by each specific field name?
2
4322
by: alex | last post by:
I'm building a Resty interface and i'm trying to POST data from a web page via a normal web form with method="POST" in it's form tag. When i submit the data to my resource the variable $_SERVER reports "GET" and there is a $_SERVER which reports "POST". The resource pages are accessed using the apache 404 error page: - The web page gets the request (http://myserver/path/to/my/resource)
4
4889
by: arorap | last post by:
I've mod_php installed with Apache 2.2. In one of my folders, I'm using the cgihandler as the PythonHandler as my target host runs python only as CGI. Here cgi.FieldStorage() doesn't seem to work. I can see the form data in sys.stdin but cgi.FieldStorage() returns an empty dictionary. Here's the code for the test script I am posting to - -- #!/usr/bin/python
0
10818
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10526
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6972
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5641
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4436
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.