Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI, POST/GET problem 1

Status
Not open for further replies.

ksvinod

Programmer
Apr 4, 2006
6
0
0
US
There is a CGIHTTPServer running on my machine. I wrote 2 python scripts, one will take the user input data and the other will process it. I tried using both GET and POST method types to post my data in the first script, but I don't know whats happening, the data is never received by the second sript.

I am using my machine for both server and client. For security reasons I am using port 8090 and not the default port for http. when I submit my data with GET option I can see it at the end of URL, but even then my second script does not read what I am sending.
I am just creating an instance of field storage and then calling the methods on it and printing the fieldNameList. But the list is always empty.

-----------------------------
fm =cgi.FieldStorage()
fieldNameList = fm.keys()
----------------------------
I have tried the basic examples straight from the book, but even then it always shows empty list.

I am wondering if there is some problem with python library which is running my web server.

To make sure my data is being sent properly I wrote a small server program and was running it on the same machine from DOS prompt. When I tried to run my first script to talk to this new server, it did display what I am sending.
I am unable to figure out what is the problem with CGIHTTPServer or the RequestHandler. I am just 2 weeks old in python and WebServer stuff.

Someone let me know if I am doing some basic mistake.

I also executed the cgi.test method giving a name and addr in the URL but I still see that for "Form Contents:" the output is "No form fields"

I am posting this problem here in this forum278. Previuosly it was in the same site but at different forum.

Thanks
Vinod
 
I also have a similar problem:

I have a cgi program in Python that genereates an HTML page with a form with hidden fields whose values are set via the following code, and when I Submit the form back to my cgi program the usernameH and passwordH values are NOT in the keys!:

Code:
##Print hidden "usernameH", "passwordH", "timeH", "checksumH", and toPageH, fields with value attribs
    print"""
    <input name="usernameH" type="hidden" id="usernameH" value="%s">
    <input name="passwordH" type="hidden" id="passwordH" value="%s">
    <input name="timeH" type="hidden" id="timeH" value="%f">
    <input name="checksumH" type="hidden" id="checksumH" value="%s"></p>
    <input name="toPageH" type="hidden" id="toPageH" value="queryPage"></p>
    <p>
    """%(usernameH, passwordH, timeH, checksumH)

The Submit action is handled with bits of javascript that follow:
Code:
<!--javascript function that returns true if username and password lengths are both greater than zero-->

<script language="JavaScript">
function validate() {
    if (loginForm.username.value.length > 0 && loginForm.password.value.length > 0){return true;}
    else{return false;}
    }
    </script>

and:

Code:
<FORM name="loginForm" ACTION="hw6mod.cgi" METHOD="POST" onsubmit=" if(!validate()){
    alert('Your username and/or password is blank.'); return false; }">

Wwhen I Submit the form back to my cgi program the usernameH and passwordH values are NOT in the keys!
Code:
form = cgi.FieldStorage()
myKeys = form.keys()
def printKeys(myKeys):
    for key in myKeys:
        print """<p>key: %s, value: %s type: %s</p>"""%(key, form[key].value, type(form[key].value))

What's going wrong?

Thanks!
 
By the way, I've seen questions like ours in this thread in other forums across the internet. Each time, there are no replies. It seems that no one cares to help people with this problem. I've had my question in two other forums for days with no replies, and other people have had their question posted for weeks with no replies. I am hoping the Tek-Tips community is more helpful than at other communities :)

Thanks!
 
Hi BcNexus,
Me and my boss found the problem and fixed it locally. There is a problem in Python Lib for CGIHTTPServer.py and cgi.py files. The file is unable to send the environment variables through the fork. It was not workiing on windows too, so we had to write an XML file and send it through a pipe. Its not a small fix though. It took lots of my time. Now we are trying to fix the fork itself, as soon as we fix, we will send the relevant lib files to python.

Thanks
Vinod
 
Thank you! What web server are you using and what version of python are you using?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top