Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > cgi.FieldStorage() not working on Windows

Reply
Thread Tools

cgi.FieldStorage() not working on Windows

 
 
arorap
Guest
Posts: n/a
 
      06-12-2007
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= http://www.velocityreviews.com/forums/(E-Mail Removed)
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.

 
Reply With Quote
 
 
 
 
Graham Dumpleton
Guest
Posts: n/a
 
      06-12-2007
On Jun 13, 1:17 am, arorap <(E-Mail Removed)> wrote:
> 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= (E-Mail Removed)
> 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

 
Reply With Quote
 
 
 
 
arorap
Guest
Posts: n/a
 
      06-13-2007
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 <(E-Mail Removed)>
wrote:
> On Jun 13, 1:17 am,arorap<(E-Mail Removed)> wrote:
>
>
>
> > 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= (E-Mail Removed)
> > 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



 
Reply With Quote
 
Graham Dumpleton
Guest
Posts: n/a
 
      06-13-2007
On Jun 13, 12:58 pm, arorap <(E-Mail Removed)> wrote:
> 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 <(E-Mail Removed)>
> wrote:
>
> > On Jun 13, 1:17 am,arorap<(E-Mail Removed)> wrote:

>
> > > 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= (E-Mail Removed)
> > > 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.


 
Reply With Quote
 
arorap
Guest
Posts: n/a
 
      06-13-2007
OOps .. yes I mean mod_python. I've been using PHP way too long ..
hence the typo


On Jun 13, 4:01 am, Graham Dumpleton <(E-Mail Removed)>
wrote:
> On Jun 13, 12:58 pm,arorap<(E-Mail Removed)> wrote:
>
> > 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 <(E-Mail Removed)>
> > wrote:

>
> > > On Jun 13, 1:17 am,arorap<(E-Mail Removed)> wrote:

>
> > > > 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= (E-Mail Removed)
> > > > 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 -



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DebugView help not working on Windows XP X64 Pro and Windows 7 x64 (?) Skybuck Flying Windows 64bit 4 08-11-2009 09:41 PM
netvmini.sys still not working on Windows 7 even after driver signing disabled ?! (Windows debug mode necessary for debug drivers ???) Skybuck Flying Windows 64bit 3 08-09-2009 05:54 AM
wifi not working on new hp, or not working after live update =?Utf-8?B?RHJhZ29ueA==?= Wireless Networking 1 10-01-2005 11:17 PM
Cookies working on intranet but NOT working on Internet Martin Heuckeroth ASP .Net 5 04-01-2005 01:37 AM
Regular Expression validators NOT working, Required Field validators ARE working Ratman ASP .Net 0 09-14-2004 09:36 PM



Advertisments