Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 766001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:58:33+00:00 2026-05-14T16:58:33+00:00

This problem is probably embarrassingly simple. I’m trying to give python a spin. I

  • 0

This problem is probably embarrassingly simple.

I’m trying to give python a spin. I thought a good way to start doing that would be to create a simple cgi script to process some form data and do some magic. My python script is executed properly by apache using mod_python, and will print out whatever I want it to print out.

My only problem is that cgi.FieldStorage() is always empty. I’ve tried using both POST and GET. Each trial I fill out both form fields.

<form action="pythonScript.py" method="POST" name="ARGH">
<input name="TaskName" type="text" />
<input name="TaskNumber" type="text" />
<input type="submit" />
</form>

If I change the form to point to a perl script it reports the form data properly. The python page always gives me the same result: number of keys: 0

#!/usr/bin/python

    import cgi

    def index(req):

            pageContent = """<html><head><title>A page from"""
            pageContent += """Python</title></head><body>"""
            form = cgi.FieldStorage()
            keys = form.keys()
            keys.sort()
            pageContent += "<br />number of keys: "+str(len(keys))
            for key in keys:
                    pageContent += fieldStorage[ key ].value
            pageContent += """</body></html>"""
            return pageContent

I’m using Python 2.5.2 and Apache/2.2.3. This is what’s in my apache conf file (and my script is in /var/www/python):

   <Directory /var/www/python/>
      Options FollowSymLinks +ExecCGI
      Order allow,deny
      allow from all
      AddHandler mod_python .py
      PythonHandler mod_python.publisher
    </Directory>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:58:34+00:00Added an answer on May 14, 2026 at 4:58 pm

    Your problem is that you’re mixing two different approaches: CGI and mod_python. You declare your script as a mod_python publisher, which is why its index method gets called — and which also makes it a module, not a script.

    If you were using CGI, you would remove the mod_python directives from your Apache configuration, just leave the ExecCGI, and either rename the script to have the .cgi extension or set the handler for the .py extension to be CGI, as well. Then your script would be executed as a script, which means the index function you defined in your script wouldn’t be executed unless you called it from the toplevel of the script.

    As I recall — but it’s been a long time since I bothered with mod_python — if you want to use mod_python instead, you should be using mod_python.util.FieldStorage instead of cgi.FieldStorage to access the POST data.

    All that said, a much better choice for bare-bones web stuff is WSGI, for example through mod_wsgi. And usually a better choice than bare-bones web stuff is using a web framework, like Django, TurboGears, Pylons, or one of the many others listed on, for example, the web frameworks page on wiki.python.org

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok.. So probably an example is a good way to explain this problem So
I think this problem is probably a simple solution. Im trying to use Validation
OK, this is probably very basic, but I can't find the problem. I'm trying
There is probably a simple solution to this problem I've been having all night.
This problem is probably very simple to solve but it is not clear to
The solution to this problem is probably pretty simple, but I need some help.
Problem : This is a probably a very basic question, but how do I
This is probably really stupid but i can't find the problem with my code.
This is a fairly common problem, it probably has a name, I just don't
This is probably an easy one, but I'm missing something I guess. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.