473,507 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Way to distinguish between POST and GET data in Python CGIs?

Hi all,

I've been experimenting with Python CGIs, and more recently mod_python.
The FieldStorage class used by Python's cgi module and mod_python's
utility library allows form data sent by a user's browser to be easily
accessed, but doesn't appear to provide any method of distinguishing
between data sent by POST and data sent by GET.

Coming from PHP, where these two types of input are available in
separate $_POST and $_GET arrays, this is causing me some concern.
Although I do not see this as a security flaw (I will still be
validating data no matter where it came from) I have always preferred to
restrict some types of input to GET and others to POST - for example,
any script that modifies data on the server in some way should use POST
rather than GET to prevent accidental modifications being caused by
user's bookmarking strange pages.

Does anyone know of a cgi style module for Python that can distinguish
between the two types of data? I'd also be interested in finding out the
reasons this functionality was excluded from the cgi module in the first
place.

Best regards,

Simon Willison

Jul 18 '05 #1
1 2818
Hi Simon,

Regarding mod_python:
* Check req.method in ('GET', 'POST').
* GET variable strings are accessible via
req.args,
req.parsed_uri[apache.URI_QUERY], or
req.subprocess_env['QUERY_STRING'] after calling req.add_common_vars().
* POST variable strings are in the client's request body, accessible via
req.read()
* The variable list strings can be parsed using functions in the cgi
and urllib modules.

Viewing mod_python as an Apache interface which accomodates
web-scripting instead of (just) a web-scripting tool helps
considerably. Think "light on the context, heavy on the construct."
Example:

4.5.3: "The request object is a Python mapping to the Apache
request_rec structure. When a handler is invoked, it is always
passed a single argument - the request object."

See http://httpd.apache.org/dev/apidoc/a...quest_rec.html for the
structure's nitty grit.

Wearing my Clueless CGI Apologist cap, I believe that it is the
server's duty to set environment variables (like REQUEST_METHOD) and
call an appropriate script with a query string (close enough). In
other words, the script's only *required input* is the query string
itself. Since environment (or "meta") variable accessibility is
"system defined," a frugal cgi module was a safe bet. Just guessing.

Aloha,
the poiboy
Jul 18 '05 #2

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

Similar topics

2
8053
by: Dfenestr8 | last post by:
Hi. I'm just a hobbyist and I like mucking around with cgi scripts. Here's the script I've been using...... >#! /usr/bin/python > >import BaseHTTPServer >import CGIHTTPServer
5
1548
by: black | last post by:
Howdy everyone~ i heard Python could be used in web programming and aftering searching many docs just found something on Python and CGI. the fact is i know nothing about CGI and most of my...
2
1283
by: Adayapalam Appaiah Kumaraswamy | last post by:
Hello Python users! I am a Python beginner. I have written a CGI script in Python which I want others to see, test and comment about. However, I do not have a website from which I can provide it...
5
1762
by: Michael Foord | last post by:
I've come across a couple of 'features' in Python standard libraries - and I'm not sure if they're meant to be there... or if they're bugs... One in urllib2 and one in cgi. >>> from urllib2...
5
1721
by: Peter Clark | last post by:
Think of something like MyYahoo: a personalized portal with news aggregator, weather forecast, comics, etc. Now instead of visiting a web site, think of all of it being sent daily as an email. It...
7
1385
by: Daniel Bickett | last post by:
I've been trying to convince my host to install python/mod_python on his server for a while now, however there are a number of reasons he is reluctant to do so, which I will outline here: 1. His...
1
1778
by: Fuzzyman | last post by:
There is a `web design` group over on google-groups. http://groups-beta.google.com/group/wd It's brief is for ``Discussion of web design (html, php, flash, wysiwig, cgi, perl, python, css,...
12
2321
by: rurpy | last post by:
Is there an effcient way (more so than cgi) of using Python with Microsoft IIS? Something equivalent to Perl-ISAPI?
14
2042
by: ccdetail | last post by:
http://www.tiobe.com/index.htm?tiobe_index Python is the 7th most commonly used language, up from 8th. The only one gaining ground besides VB in the top 10. We're glad, our app is written in...
0
7223
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,...
0
7110
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...
0
7314
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,...
0
7372
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...
0
5623
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,...
0
3191
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...
0
1540
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 ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
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...

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.