473,396 Members | 2,004 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,396 software developers and data experts.

cgi.FieldStorage() not working on Windows

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

import os
import cgi
import sys

print "Content Type: text/plain\n\n"
print "Hello CGI World !\n"

for key in os.environ:
print key + "= " + os.environ[key]

print cgi.FieldStorage()

print sys.stdin.read()
--

And here's the output I see ..

--
Hello CGI World !

HTTP_REFERER= http://learnpython/form.htm
SERVER_SOFTWARE= Apache/2.2.4 (Win32) mod_python/3.3.1 Python/2.5.1
SCRIPT_NAME= /mptest.py
SERVER_SIGNATURE=
REQUEST_METHOD= POST
SERVER_PROTOCOL= HTTP/1.1
QUERY_STRING= abc=ayz
PATH= C:\Program Files\Internet Explorer;;C:\WINDOWS\system32;C:
\WINDOWS;C:\WINDOWS\System32\Wbem;q:\bin;m:\cm\cle arcase\bin;M:\PERL\NT
\EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\B IN;m:\perl\nt\exec
\bin;m:\cm\clearcase\utils;q:\bin;m:\opus;m:\tvcs; C:\highc331\bin;C:
\Program Files\Rational\ClearCase\bin;C:\Program Files\Rational\common
CONTENT_LENGTH= 86
HTTP_USER_AGENT= Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
HTTP_CONNECTION= Keep-Alive
SERVER_NAME= learnpython
REMOTE_ADDR= 127.0.0.1
PATHEXT= .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
SERVER_PORT= 80
SERVER_ADDR= 127.0.0.1
DOCUMENT_ROOT= D:/Projects/LearnPython/www
COMSPEC= C:\WINDOWS\system32\cmd.exe
SCRIPT_FILENAME= D:/Projects/LearnPython/www/mptest.py
SERVER_ADMIN= pu**********@tekelec.com
HTTP_HOST= learnpython
SystemRoot= C:\WINDOWS
HTTP_CACHE_CONTROL= no-cache
REQUEST_URI= /mptest.py?abc=ayz
HTTP_ACCEPT= */*
WINDIR= C:\WINDOWS
GATEWAY_INTERFACE= Python-CGI/1.1
REMOTE_PORT= 1081
HTTP_ACCEPT_LANGUAGE= en-us
CONTENT_TYPE= application/x-www-form-urlencoded
HTTP_ACCEPT_ENCODING= gzip, deflate

FieldStorage(None, None, [])

firstName=puneet&address=hawaii
--

I am posting to this script using a form with two text fields named
firstName and address.

any clue where am I going wrong ?

thanks,

regards,
-Puneet.

Jun 12 '07 #1
4 4844
On Jun 13, 1:17 am, arorap <aro...@gmail.comwrote:
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

import os
import cgi
import sys

print "Content Type: text/plain\n\n"
print "Hello CGI World !\n"

for key in os.environ:
print key + "= " + os.environ[key]

print cgi.FieldStorage()

print sys.stdin.read()
--

And here's the output I see ..

--
Hello CGI World !

HTTP_REFERER=http://learnpython/form.htm
SERVER_SOFTWARE= Apache/2.2.4 (Win32)mod_python/3.3.1 Python/2.5.1
SCRIPT_NAME= /mptest.py
SERVER_SIGNATURE=
REQUEST_METHOD= POST
SERVER_PROTOCOL= HTTP/1.1
QUERY_STRING= abc=ayz
PATH= C:\Program Files\Internet Explorer;;C:\WINDOWS\system32;C:
\WINDOWS;C:\WINDOWS\System32\Wbem;q:\bin;m:\cm\cle arcase\bin;M:\PERL\NT
\EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\B IN;m:\perl\nt\exec
\bin;m:\cm\clearcase\utils;q:\bin;m:\opus;m:\tvcs; C:\highc331\bin;C:
\Program Files\Rational\ClearCase\bin;C:\Program Files\Rational\common
CONTENT_LENGTH= 86
HTTP_USER_AGENT= Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
HTTP_CONNECTION= Keep-Alive
SERVER_NAME= learnpython
REMOTE_ADDR= 127.0.0.1
PATHEXT= .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
SERVER_PORT= 80
SERVER_ADDR= 127.0.0.1
DOCUMENT_ROOT= D:/Projects/LearnPython/www
COMSPEC= C:\WINDOWS\system32\cmd.exe
SCRIPT_FILENAME= D:/Projects/LearnPython/www/mptest.py
SERVER_ADMIN= puneet.ar...@tekelec.com
HTTP_HOST= learnpython
SystemRoot= C:\WINDOWS
HTTP_CACHE_CONTROL= no-cache
REQUEST_URI= /mptest.py?abc=ayz
HTTP_ACCEPT= */*
WINDIR= C:\WINDOWS
GATEWAY_INTERFACE= Python-CGI/1.1
REMOTE_PORT= 1081
HTTP_ACCEPT_LANGUAGE= en-us
CONTENT_TYPE= application/x-www-form-urlencoded
HTTP_ACCEPT_ENCODING= gzip, deflate

FieldStorage(None, None, [])

firstName=puneet&address=hawaii
--

I am posting to this script using a form with two text fields named
firstName and address.

any clue where am I going wrong ?
You don't need mod_python/cgihandler to run CGI scripts. Rather than
bring mod_python into the picture and confuse things, set up Apache to
run your script as a traditional CGI script instead.

BTW, the fact that mod_python is loaded means that CGI scripts aren't
the only way of using Python available to you as you seem to think.
So, suggest you do some research as to what the differences are
between CGI and mod_python.

Graham

Jun 13 '07 #2
Thanks for your reply.

The reason I want to run it as CGI (even though mod_php is available
on my local computer) is that the target machine to which I will
finally be uploading my scripts runs CGI.

cgihandler should work just like CGI. Any clue why the
cgi.FieldStorage()might not be working ?
On Jun 12, 7:59 pm, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:
On Jun 13, 1:17 am,arorap<aro...@gmail.comwrote:
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
import os
import cgi
import sys
print "Content Type: text/plain\n\n"
print "Hello CGI World !\n"
for key in os.environ:
print key + "= " + os.environ[key]
print cgi.FieldStorage()
print sys.stdin.read()
--
And here's the output I see ..
--
Hello CGI World !
HTTP_REFERER=http://learnpython/form.htm
SERVER_SOFTWARE= Apache/2.2.4 (Win32)mod_python/3.3.1 Python/2.5.1
SCRIPT_NAME= /mptest.py
SERVER_SIGNATURE=
REQUEST_METHOD= POST
SERVER_PROTOCOL= HTTP/1.1
QUERY_STRING= abc=ayz
PATH= C:\Program Files\Internet Explorer;;C:\WINDOWS\system32;C:
\WINDOWS;C:\WINDOWS\System32\Wbem;q:\bin;m:\cm\cle arcase\bin;M:\PERL\NT
\EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\B IN;m:\perl\nt\exec
\bin;m:\cm\clearcase\utils;q:\bin;m:\opus;m:\tvcs; C:\highc331\bin;C:
\Program Files\Rational\ClearCase\bin;C:\Program Files\Rational\common
CONTENT_LENGTH= 86
HTTP_USER_AGENT= Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
HTTP_CONNECTION= Keep-Alive
SERVER_NAME= learnpython
REMOTE_ADDR= 127.0.0.1
PATHEXT= .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
SERVER_PORT= 80
SERVER_ADDR= 127.0.0.1
DOCUMENT_ROOT= D:/Projects/LearnPython/www
COMSPEC= C:\WINDOWS\system32\cmd.exe
SCRIPT_FILENAME= D:/Projects/LearnPython/www/mptest.py
SERVER_ADMIN= puneet.ar...@tekelec.com
HTTP_HOST= learnpython
SystemRoot= C:\WINDOWS
HTTP_CACHE_CONTROL= no-cache
REQUEST_URI= /mptest.py?abc=ayz
HTTP_ACCEPT= */*
WINDIR= C:\WINDOWS
GATEWAY_INTERFACE= Python-CGI/1.1
REMOTE_PORT= 1081
HTTP_ACCEPT_LANGUAGE= en-us
CONTENT_TYPE= application/x-www-form-urlencoded
HTTP_ACCEPT_ENCODING= gzip, deflate
FieldStorage(None, None, [])
firstName=puneet&address=hawaii
--
I am posting to this script using a form with two text fields named
firstName and address.
any clue where am I going wrong ?

You don't need mod_python/cgihandler to run CGI scripts. Rather than
bring mod_python into the picture and confuse things, set up Apache to
run your script as a traditional CGI script instead.

BTW, the fact that mod_python is loaded means that CGI scripts aren't
the only way of using Python available to you as you seem to think.
So, suggest you do some research as to what the differences are
between CGI and mod_python.

Graham

Jun 13 '07 #3
On Jun 13, 12:58 pm, arorap <aro...@gmail.comwrote:
Thanks for your reply.

The reason I want to run it as CGI (even though mod_php is available
on my local computer
Why do you keep mentioning mod_php, surely you mean mod_python.
is that the target machine to which I will
finally be uploading my scripts runs CGI.

cgihandler should work just like CGI.
I wouldn't rely on it being exactly the same. The way it works uses a
number of kludges. Also, the mod_python.cgihandler code in mod_python
doesn't really get much attention from mod_python developers anymore
and not sure if it was even specifically retested when mod_python 3.3
was released.
Any clue why the
cgi.FieldStorage()might not be working ?
Have no idea why it doesn't work as works as written on MacOS X even
when mod_python.cgihandler is used.

You'll have to get someone else who has Windows to try it. You might
be better off going to the mod_python mailing list to get help, or
just use plain old CGI instead since using mod_python isn't really
going to gain you much anyway.

Graham
On Jun 12, 7:59 pm, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:
On Jun 13, 1:17 am,arorap<aro...@gmail.comwrote:
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
import os
import cgi
import sys
print "Content Type: text/plain\n\n"
print "Hello CGI World !\n"
for key in os.environ:
print key + "= " + os.environ[key]
print cgi.FieldStorage()
print sys.stdin.read()
--
And here's the output I see ..
--
Hello CGI World !
HTTP_REFERER=http://learnpython/form.htm
SERVER_SOFTWARE= Apache/2.2.4 (Win32)mod_python/3.3.1 Python/2.5.1
SCRIPT_NAME= /mptest.py
SERVER_SIGNATURE=
REQUEST_METHOD= POST
SERVER_PROTOCOL= HTTP/1.1
QUERY_STRING= abc=ayz
PATH= C:\Program Files\Internet Explorer;;C:\WINDOWS\system32;C:
\WINDOWS;C:\WINDOWS\System32\Wbem;q:\bin;m:\cm\cle arcase\bin;M:\PERL\NT
\EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\B IN;m:\perl\nt\exec
\bin;m:\cm\clearcase\utils;q:\bin;m:\opus;m:\tvcs; C:\highc331\bin;C:
\Program Files\Rational\ClearCase\bin;C:\Program Files\Rational\common
CONTENT_LENGTH= 86
HTTP_USER_AGENT= Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
HTTP_CONNECTION= Keep-Alive
SERVER_NAME= learnpython
REMOTE_ADDR= 127.0.0.1
PATHEXT= .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
SERVER_PORT= 80
SERVER_ADDR= 127.0.0.1
DOCUMENT_ROOT= D:/Projects/LearnPython/www
COMSPEC= C:\WINDOWS\system32\cmd.exe
SCRIPT_FILENAME= D:/Projects/LearnPython/www/mptest.py
SERVER_ADMIN= puneet.ar...@tekelec.com
HTTP_HOST= learnpython
SystemRoot= C:\WINDOWS
HTTP_CACHE_CONTROL= no-cache
REQUEST_URI= /mptest.py?abc=ayz
HTTP_ACCEPT= */*
WINDIR= C:\WINDOWS
GATEWAY_INTERFACE= Python-CGI/1.1
REMOTE_PORT= 1081
HTTP_ACCEPT_LANGUAGE= en-us
CONTENT_TYPE= application/x-www-form-urlencoded
HTTP_ACCEPT_ENCODING= gzip, deflate
FieldStorage(None, None, [])
firstName=puneet&address=hawaii
--
I am posting to this script using a form with two text fields named
firstName and address.
any clue where am I going wrong ?
You don't need mod_python/cgihandler to run CGI scripts. Rather than
bring mod_python into the picture and confuse things, set up Apache to
run your script as a traditional CGI script instead.
BTW, the fact that mod_python is loaded means that CGI scripts aren't
the only way of using Python available to you as you seem to think.
So, suggest you do some research as to what the differences are
between CGI and mod_python.
Jun 13 '07 #4
OOps .. yes I mean mod_python. I've been using PHP way too long :P ..
hence the typo
On Jun 13, 4:01 am, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:
On Jun 13, 12:58 pm,arorap<aro...@gmail.comwrote:
Thanks for your reply.
The reason I want to run it as CGI (even though mod_php is available
on my local computer

Why do you keep mentioning mod_php, surely you mean mod_python.
is that the target machine to which I will
finally be uploading my scripts runs CGI.
cgihandler should work just like CGI.

I wouldn't rely on it being exactly the same. The way it works uses a
number of kludges. Also, the mod_python.cgihandler code in mod_python
doesn't really get much attention from mod_python developers anymore
and not sure if it was even specifically retested when mod_python 3.3
was released.
Any clue why the
cgi.FieldStorage()might not be working ?

Have no idea why it doesn't work as works as written on MacOS X even
when mod_python.cgihandler is used.

You'll have to get someone else who has Windows to try it. You might
be better off going to the mod_python mailing list to get help, or
just use plain old CGI instead since using mod_python isn't really
going to gain you much anyway.

Graham
On Jun 12, 7:59 pm, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:
On Jun 13, 1:17 am,arorap<aro...@gmail.comwrote:
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
import os
import cgi
import sys
print "Content Type: text/plain\n\n"
print "Hello CGI World !\n"
for key in os.environ:
print key + "= " + os.environ[key]
print cgi.FieldStorage()
print sys.stdin.read()
--
And here's the output I see ..
--
Hello CGI World !
HTTP_REFERER=http://learnpython/form.htm
SERVER_SOFTWARE= Apache/2.2.4 (Win32)mod_python/3.3.1 Python/2.5.1
SCRIPT_NAME= /mptest.py
SERVER_SIGNATURE=
REQUEST_METHOD= POST
SERVER_PROTOCOL= HTTP/1.1
QUERY_STRING= abc=ayz
PATH= C:\Program Files\Internet Explorer;;C:\WINDOWS\system32;C:
\WINDOWS;C:\WINDOWS\System32\Wbem;q:\bin;m:\cm\cle arcase\bin;M:\PERL\NT
\EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\B IN;m:\perl\nt\exec
\bin;m:\cm\clearcase\utils;q:\bin;m:\opus;m:\tvcs; C:\highc331\bin;C:
\Program Files\Rational\ClearCase\bin;C:\Program Files\Rational\common
CONTENT_LENGTH= 86
HTTP_USER_AGENT= Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
HTTP_CONNECTION= Keep-Alive
SERVER_NAME= learnpython
REMOTE_ADDR= 127.0.0.1
PATHEXT= .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
SERVER_PORT= 80
SERVER_ADDR= 127.0.0.1
DOCUMENT_ROOT= D:/Projects/LearnPython/www
COMSPEC= C:\WINDOWS\system32\cmd.exe
SCRIPT_FILENAME= D:/Projects/LearnPython/www/mptest.py
SERVER_ADMIN= puneet.ar...@tekelec.com
HTTP_HOST= learnpython
SystemRoot= C:\WINDOWS
HTTP_CACHE_CONTROL= no-cache
REQUEST_URI= /mptest.py?abc=ayz
HTTP_ACCEPT= */*
WINDIR= C:\WINDOWS
GATEWAY_INTERFACE= Python-CGI/1.1
REMOTE_PORT= 1081
HTTP_ACCEPT_LANGUAGE= en-us
CONTENT_TYPE= application/x-www-form-urlencoded
HTTP_ACCEPT_ENCODING= gzip, deflate
FieldStorage(None, None, [])
firstName=puneet&address=hawaii
--
I am posting to this script using a form with two text fields named
firstName and address.
any clue where am I going wrong ?
You don't need mod_python/cgihandler to run CGI scripts. Rather than
bring mod_python into the picture and confuse things, set up Apache to
run your script as a traditional CGI script instead.
BTW, the fact that mod_python is loaded means that CGI scripts aren't
the only way of using Python available to you as you seem to think.
So, suggest you do some research as to what the differences are
between CGI and mod_python.- Hide quoted text -

- Show quoted text -

Jun 13 '07 #5

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

Similar topics

1
by: Al Stoltz | last post by:
Greetings all. I've got a small web application (just a web interface to a MS-access database) and I recently upgraded ActiveState's python dist. from 2.2 to their latest (2.3.2 I think). In the...
0
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. ...
1
by: Austyn Bontrager | last post by:
Should cgi.FieldStorage examine the environment variable REDIRECT_REQUEST_METHOD before examining REQUEST_METHOD? I'm running Apache, and write my CGI scripts in Python. I have this in a...
1
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)...
1
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...
1
by: Graeme Matthew | last post by:
Hi all I do a CGI post, I am using CGI.FieldStorage(), I obtain the values etc al works fine. I now need to take the same posted data and resubmit it to a remote server i.e I need to rebuild...
4
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,...
3
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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
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
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,...

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.