473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Passing arguments to python from URL

I've got a python cgi-bin application which produces an apache web page. I
want to pass arguments to it on the URL line, but the parameters are not
getting passed along to python properly.

I've been using sys.argv to pick up command line arguments, and it works
fine when I call the python program from the command line. Unfortunately,
when I pass data to the program from the URL, many of the parameters are
being clobbered and **NOT** passed to python.
For example: "http://www.nobody.com/cgi-bin/program.py?sort=ascending" only
passes the parameter "/usr/lib/cgi-bin/program.py".

However, "http://www.nobody.com/cgi-bin/program.py?sort%20ascending" passes
a 2-place tuple of ("/usr/lib/cgi-bin/program.py", "sort ascending").

Somehow, adding the "=" in the argument list prevents **ANY** parameters
from being passed to python. I could re-write the python program to work
around this, but I sure would like to understand it first.
Can anybody explain this weird behavior?

(Please reply to the news group... my eMail address is a phony to prevent
spam.)
Jul 18 '05 #1
1 8335
Casey Bralla <No****@Nowhere.com> writes:
I've got a python cgi-bin application which produces an apache web page. I
want to pass arguments to it on the URL line, but the parameters are not
getting passed along to python properly.

I've been using sys.argv to pick up command line arguments, and it works
fine when I call the python program from the command line. Unfortunately,
when I pass data to the program from the URL, many of the parameters are
being clobbered and **NOT** passed to python.

For example: "http://www.nobody.com/cgi-bin/program.py?sort=ascending" only
passes the parameter "/usr/lib/cgi-bin/program.py".
This is expected.
However, "http://www.nobody.com/cgi-bin/program.py?sort%20ascending" passes
a 2-place tuple of ("/usr/lib/cgi-bin/program.py", "sort
ascending").
I don't know why this actually works, it's not (AFAIK) defined behaviour.
Somehow, adding the "=" in the argument list prevents **ANY** parameters
from being passed to python. I could re-write the python program to work
around this, but I sure would like to understand it first.


You're going to have to rewrite. CGI scripts get their arguments
passed to them through the environment, not on the command line.
QUERY_STRING, for instance, will hold the query string (the stuff
after the ?).

Use Python's cgi module to make things easier on yourself; the
documentation has a good overview:
http://www.python.org/doc/2.4/lib/module-cgi.html

In this case, your script would look something like this:

import cgi
form = cgi.FieldStorage()
if form.getvalue('sort') == 'ascending':
... sort in ascending order ...

etc.

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Jul 18 '05 #2

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

Similar topics

4
by: Martin Lucas-Smith | last post by:
Having re-read www.php.net/functions.arguments recently, the notion of passing arguments by reference to a function makes a lot more sense now. However, my question is: is there any difference in...
20
by: Gregory Piñero | last post by:
Hey guys, would someone mind giving me a quick rundown of how references work in Python when passing arguments into functions? The code below should highlight my specific confusion: <code> ...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
3
by: Mantorok | last post by:
Hi all I'm pretty new to ASP.Net, is it possible to pass arguments (maybe objects too) to web forms without using a querystring in the URL? Thanks Kev
4
by: Scott M. | last post by:
Does C# support passing arguments ByVal & ByRef? If so, what is the default (ByVal?)? And, if so, how do you explicitly specify either? Thanks.
0
by: Gonçalo Rodrigues | last post by:
Hi all, I have a single-rooted hierarchy of heap-allocated objects -- call the root Object. These objects are handled via a smart pointer template Reference<T>. Basically, Reference<Tis a...
1
by: 418928 | last post by:
Hi everybody, I understand that the standard way of passing arguments to a web page using javascript is "<url>?<arguments separated with "&" and values with "=">. Then, I can use...
4
by: phoolpreet | last post by:
hi guys i m stuck with the problem of passing arguments to main. we can define argc and argv and put statements in main that use these arguments. but how to set these value while running a...
6
by: =?iso-8859-1?q?Luis_M._Gonz=E1lez?= | last post by:
Please forgive me if what I'm asking is non sense... I created a little program to authomate the creation of the "setup.py" script for py2exe. It simply prompts for the main executable script...
1
by: Jean Paul Mertens | last post by:
Hello, Is there a simple way for passing arguments to applications deployed with ClickOnce and having off-line capabilities. My app takes arguments if I start it with the whole path to it...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.