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!

Form Data POST/GET problem

Status
Not open for further replies.

ksvinod

Programmer
Apr 4, 2006
6
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"


Thanks
Vinod
 
are your fields inside your form tags? Don't know python myself?

I normally run a webserver on port80 on the local machine, and access it as never had a problem

--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Yes paul, my fields are inside the form tags and I specify my ip in the URL, due to some reason I won't get connected if I use "localhost" in my URL.
This is an HTML page I am using python script to generate the HTML output, so you are good even if you don't know python, but you should be aware of CGI and specific to support of python for CGI

Thnx
Vinod
 
Post your python code, and we'll see if someone can't sort it out. A really simplified example if you have to hand would be good.

Regards
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
The below content is for first script

import cgi

#import cgitb; cgitb.enable()

print "Content-type: text/html"
print

print "<html>"
print "<head><title>From CGI Test Program</title></head>"
print "<body>"
print "<h1>"
print "WOW! I was created by a CGI program!!"
print "</h1>"
print "<form action= method=get>"
print "<strong> Name: </strong>"
print "<input type=html name=user size=25 maxlength=35 />"
print "<br/><br/><br/>"
print "<input type='submit' value= 'Submit' />"
print "</form>"
print "</body>"
print "</html>"




Here is the second script invoked by first script

import cgi
import cgitb; cgitb.enable()
import os

#cgi.test()

env = os.environ
import cgitb; cgitb.enable()

fm = cgi.FieldStorage()
fieldNameList = fm.keys()

print "Content-type: text/html"
print



html = """
<TITLE>This is CGI Program cgi_prg2.cgi</TITLE>
<H1>Greetings</H1>
<HR/>
<p>%s</p>
<HR/> """


if not fm.has_key('user'):
print html % 'UserName field not found - Valid Field Names: ' + str(fieldNameList)
else:
print html % ("Hello, %s." % fm['user'].value)
 
Code:
html = """
triple quotes, is this normal python behaviour? If not there should be some escaping, or concatenation going on.


Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Hi Feherke/paul,
I tried even with text option like below
print "<input type=text name=user size=25 maxlength=35 />"

It didn't work.

The triple quotes are basically for holding strings and the end of line is not needed to be explicitly specified when you use matching """ or '''.

Thanks
Vinod
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top