cgi.FieldStorage() not working on Windows

Discussion in 'Python' started by arorap, Jun 12, 2007.

  1. arorap

    arorap Guest

    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\clearcase\bin;M:\PERL\NT
    \EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\BIN;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_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.
     
    arorap, Jun 12, 2007
    #1
    1. Advertising

  2. On Jun 13, 1:17 am, arorap <> 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\clearcase\bin;M:\PERL\NT
    > \EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\BIN;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_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
     
    Graham Dumpleton, Jun 13, 2007
    #2
    1. Advertising

  3. arorap

    arorap Guest

    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 <>
    wrote:
    > On Jun 13, 1:17 am,arorap<> 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\clearcase\bin;M:\PERL\NT
    > > \EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\BIN;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_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
     
    arorap, Jun 13, 2007
    #3
  4. On Jun 13, 12:58 pm, arorap <> 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 <>
    > wrote:
    >
    > > On Jun 13, 1:17 am,arorap<> 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\clearcase\bin;M:\PERL\NT
    > > > \EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\BIN;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_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 Dumpleton, Jun 13, 2007
    #4
  5. arorap

    arorap Guest

    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 <>
    wrote:
    > On Jun 13, 12:58 pm,arorap<> 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 <>
    > > wrote:

    >
    > > > On Jun 13, 1:17 am,arorap<> 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\clearcase\bin;M:\PERL\NT
    > > > > \EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\BIN;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_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 -
     
    arorap, Jun 13, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Stoltz
    Replies:
    1
    Views:
    1,012
    Andrew Clover
    Jan 23, 2004
  2. Fred Murray

    Odd cgi.FieldStorage behavior

    Fred Murray, Mar 2, 2004, in forum: Python
    Replies:
    1
    Views:
    310
    Tim Roberts
    Mar 4, 2004
  3. python user

    libapreq2 and cgi.FieldStorage

    python user, Jul 9, 2004, in forum: Python
    Replies:
    0
    Views:
    343
    python user
    Jul 9, 2004
  4. Austyn Bontrager

    cgi.FieldStorage and REDIRECT_REQUEST_METHOD

    Austyn Bontrager, Jul 28, 2004, in forum: Python
    Replies:
    1
    Views:
    476
    Lee Harr
    Jul 28, 2004
  5. Ames Andreas (MPA/DF)
    Replies:
    0
    Views:
    286
    Ames Andreas (MPA/DF)
    Aug 5, 2004
Loading...

Share This Page