473,480 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

questions concerning cgi.FieldStorage(keep_blank_values=1)

hello,

i'm quite new to python. currently i try to write a web application with
python cgi scripts.

in this application, i need keys to be delivered with the url, some with
and some without value (for example 'script.py?key1&key2=foo'.

i've searched the internet, and already figured out that i need to give
non-empty keep_blank_values as argument to cgi.FieldStorage, to make it
not cut all the empty keywords.

anyway, this still doesn't work really good:

---snip---
form = cgi.FieldStorage(keep_blank_values=1)

print 'list keys with form.keys():'
keys = form.keys()
keys.sort()
for key in keys:
print key
---snip---

if i request the script with script.py?key1&key2=foo, it will output:
list keys with form.keys():
key2

any suggestions about how to make form.keys() contain the blank keys as
well?

bye
jonas
Jul 18 '05 #1
4 2852
Hi,

Jonas Meurer wrote:
if i request the script with script.py?key1&key2=foo, it will output:
list keys with form.keys():
key2

any suggestions about how to make form.keys() contain the blank keys
as well?


"key1" isn't a valid parameter, to supply an empty key you would write
script.py?key1=&key2=foo

Then cgi.FieldStorage also includes key1.

bye,
Daniel

--
For mail replies please use my address from
http://perplex.schmumpf.de/
http://www.gametective.de/
Jul 18 '05 #2
On 20/02/2005 Daniel Lichtenberger wrote:
any suggestions about how to make form.keys() contain the blank keys
as well?


"key1" isn't a valid parameter, to supply an empty key you would write
script.py?key1=&key2=foo

Then cgi.FieldStorage also includes key1.


great, it works. but is there no way to use single keywords as GET
argument?

bye
jonas
Jul 18 '05 #3
Jonas Meurer wrote:
"key1" isn't a valid parameter, to supply an empty key you would write
script.py?key1=&key2=foo

Then cgi.FieldStorage also includes key1.


great, it works. but is there no way to use single keywords as GET
argument?


You could manually parse the request string (CGI stores the request
string as an environment variable, you can retrieve it via
os.environ["REQUEST_STRING"]), but why not add "=1" (or "=") to your
keywords?

bye,
Daniel

--
http://perplex.schmumpf.de/
[visit for regular email address]
Jul 18 '05 #4
Jonas:
in this application, i need keys to be delivered with the url, some with and some without value (for example 'script.py?key1&key2=foo'.


You are missing an "=" sign after key1. Confront with this example:

from cgi import parse_qsl

QS = "x=1&y=2&x=3&z=&y=4"
print parse_qsl(QS)
print parse_qsl(QS, keep_blank_values=True)

which gives

[('x', '1'), ('y', '2'), ('x', '3'), ('y', '4')]
[('x', '1'), ('y', '2'), ('x', '3'), ('z', ''), ('y', '4')]

Here the blank value "z=" is converted into "z=''".
Michele Simionato

Jul 18 '05 #5

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

Similar topics

0
1060
by: Ames Andreas (MPA/DF) | last post by:
Hi, is it fair to assume that after executing the following code fs = cgi.FieldStorage(fp = somefile, keep_blank_values = 1) stream = fs.file or StringIO(fs.value) stream is a seekable copy...
1
1451
by: Robert Brewer | last post by:
I've Googled extensively, but can't figure out what might be causing my Python CGI app to zombie (yes, Tibia, the one I just announced ;). The cgi bit looks like this: def cgi_handler():...
2
13984
by: Erik Johnson | last post by:
I am trying to work with a program that is trying make an HTTP POST of text data without any named form parameter. (I don't know - is that a normal thing to do?) I need to write a CGI program that...
3
2194
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...
1
1739
by: Eddy Ilg | last post by:
I'm having problems with a python cgi script. The script just won't read any POST data. Forms with GET data work fine. Here's the script: #!/usr/bin/python import sys import os import cgi
0
1881
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...
19
2076
by: Clodoaldo Pinto Neto | last post by:
I'm just building a Python CGI Tutorial and would appreciate any feedback from the many experts in this list. Regards, Clodoaldo Pinto Neto
3
7861
by: Christopher Mocock | last post by:
Hi all, Bit of a python newbie so need a little help with a CGI script I'm trying to write. I've got it working fine as long as the fields of the form are filled in correctly, however I need to...
2
1401
by: epsilon | last post by:
All: I'm running into trouble figuring this one out. It seems that my decision routine is not working as intended. Does anyone know why my output continues to utilize the "else" portion of the...
0
6904
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
7034
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
7076
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...
1
6732
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...
0
6886
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...
0
5324
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
1294
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
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
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.