473,804 Members | 2,999 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 1826
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
1251
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
1639
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
1951
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
2122
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
1588
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
4320
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
4885
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
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
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
10319
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...
1
10303
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10070
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
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
6845
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();...
1
4282
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

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.