473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

FORM data in cgi

Greetings.
An HTML form submits it's data to a python cgi script on my server. This script accepts this POST data, and uses urllib.urlopen() to call a different cgi script (on an external server), passing this same data. I'm using cgi.FieldStorage() to create a mapping of the FORM data, then using urllib.urlencode() to turn it back into form data for urlopen().
Question - is there a more efficient way to do this?

I'm using an intermediary script because I want to be able to reformat the data returning from the external script before displaying it to the user.

TIA for your help.
--
Jp


"Don't let fear or good sense stop you."
-- Dennis Sollars
Oct 13 '05 #1
2 2269
"jponiato" <jp******@chartermi.nojunk> writes:
Greetings.
An HTML form submits it's data to a python cgi script on my server. This script accepts this POST data, and uses urllib.urlopen() to call a different cgi script (on an external server), passing this same data. I'm using cgi.FieldStorage() to create a mapping of the FORM data, then using urllib.urlencode() to turn it back into form data for urlopen().
Question - is there a more efficient way to do this?


Yes. But the question you should be asking is "Is there an easier way
to do it that's worth doing?"

Unless you're passing around files, or really huge forms, the amount
of time you spend doing decoding and encodinng the form data will be
pretty trivial. Unless you're really pressed for cycles, why bother
fixing it? And if you're really pressed for cycles, you should start
by instrumenting things to make sure that you're optimizing something
that will do you some good.

Anyway, the general idea is to skip cgi.FieldStorage, and parse the
request yourself. You'll have to deal with the headers. But you can
just grab the post data with a read(). I'm not sure you can use urllib
to send pre-encoded POST data; you'll have to check that yourself. If
not, you'll have to do the HTTP request processing by yourself. That's
not hard, though.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Oct 14 '05 #2
Mike Meyer wrote:
"jponiato" <jp******@chartermi.nojunk> writes:

Greetings.
An HTML form submits it's data to a python cgi script on my server. This script accepts this POST data, and uses urllib.urlopen() to call a different cgi script (on an external server), passing this same data. I'm using cgi.FieldStorage() to create a mapping of the FORM data, then using urllib.urlencode() to turn it back into form data for urlopen().
Question - is there a more efficient way to do this?

Yes. But the question you should be asking is "Is there an easier way
to do it that's worth doing?"

Unless you're passing around files, or really huge forms, the amount
of time you spend doing decoding and encodinng the form data will be
pretty trivial. Unless you're really pressed for cycles, why bother
fixing it? And if you're really pressed for cycles, you should start
by instrumenting things to make sure that you're optimizing something
that will do you some good.

Anyway, the general idea is to skip cgi.FieldStorage, and parse the
request yourself. You'll have to deal with the headers. But you can
just grab the post data with a read(). I'm not sure you can use urllib
to send pre-encoded POST data; you'll have to check that yourself. If
not, you'll have to do the HTTP request processing by yourself. That's
not hard, though.

<mike


In point of fact the OP (whose post wasn't threaded with your reply in
my newsreader) is actually describing a requirement for an HTTP proxy!

As you describe it, since the data stream in the request body will be
exactly the same in both cases (though the HTTP request line and headers
will differ) is possible to handle the request by having the CGI script
a direct connection to the intended destination server, parsing the
incoming headers, generating the outgoing ones, and then just relaying
the request body. The response will then have to be sent back to the
client, possibly requiring some parsing on the way, so the processing
time might come out a wash.

Of course it would be even easier to set up direct proxying through the
web server if it's something accommodating like Apache ...

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
8
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query...
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.