473,666 Members | 2,044 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 2825
Hi Simon,

Regarding mod_python:
* Check req.method in ('GET', 'POST').
* GET variable strings are accessible via
req.args,
req.parsed_uri[apache.URI_QUER Y], 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
8064
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
1555
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 projects(both of company and myself) are established with PHP and ASP. now the questions come: 1. Could Python be used in web programming ? (i guess yes ?) 2. If the answer of above is yes, then can we programms with Python in both server and client...
2
1293
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 to others. Could you please tell me where I must post the files so that other Python users can see them? Also, since it has a script, an HTML file and a few others, in which format should I post it (i.e. write them onto a message, or attach as...
5
1768
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 import urlopen >>> a = urlopen('http://www.voidspace.org.uk') >>> i = a.info() >>> for entry in i: print entry Traceback (most recent call last):
5
1728
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 does have a web interface, but mostly for selecting your content: this is my location for weather, these are the news feeds I'm interested in, these are the comics I like, save my preferences, and the server takes care of the rest. Does such a...
7
1396
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 major reason is optimization. He uses Zend's optimization of PHP as an example, and he has stated that python is rather resource consuming. 2. Another one of his points is that he is unexperienced in installing python, and he would not know how...
1
1789
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, design concepts, etc.).``, but it's very quiet. I'd love to see it become a discussion forum for Python CGIs and associated issues (web design, the http protocol etc). Regards,
12
2348
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
2072
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 python. It's free at http://pnk.com and it is a web timesheet for project accounting
0
8444
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
8356
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
8781
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
8551
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
8639
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...
0
7386
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...
0
4198
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
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.