473,320 Members | 1,810 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,320 software developers and data experts.

CGI.FieldStorage to HTML

Hi all

I do a CGI post, I am using CGI.FieldStorage(), I obtain the values etc al
works fine.

I now need to take the same posted data and resubmit it to a remote server
i.e I need to rebuild the entire raw html request.

Does anyone know if you can retrieve the entire request string before
parsing it via the cgi module? and then resubmit this to another server?
Cheers

Graeme


Jul 18 '05 #1
1 2808
"Graeme Matthew" <gr************@contrado.com.au> wrote in message news:<41***********************@per-qv1-newsreader-01.iinet.net.au>...
Hi all

I do a CGI post, I am using CGI.FieldStorage(), I obtain the values etc al
works fine.

I now need to take the same posted data and resubmit it to a remote server
i.e I need to rebuild the entire raw html request.

Does anyone know if you can retrieve the entire request string before
parsing it via the cgi module? and then resubmit this to another server?
Cheers

Graeme


Before I waffle - os.environ['QUERY_STRING'] is probably the answer
you want !!

I've been implementing a cgi proxy recently which does exactly this.
Unfortunately I haven't been able to find a way to get the entire http
request and just proxy that because the server 'parses' it puts a lot
of it into the environment. (For example any authentication headers
it's impossible to retrieve from the CGI environment).

I'm doing just what you said though and rebuilding the request from
the FieldStorage and environment variables. At the moment I'm only
proxying the User-Agent headers, although I might do a few more later
though (HTTP_REFFERER etc). You can see where I've got to with
http://www.voidspace.org.uk/atlantib....html#cgiproxy

Doing 'GET' method requests is *easy*. Rebuilding 'POST' method
requests is a bit more complicated. The code I have so far will do all
requests except file uploads (I'm working on at the moment - will be
ready soon) and I haven't tested it with list values (might work...
might not). I've also just got my head around authentication (error
401 BASIC authentication and am half way through writing the code to
implement it).

Something you might find useful is my http_test.py CGI. This shows you
all the environment variables etc when you fetch a url - useful for
working out what information you have available to you. (See
http://www.voidspace.org.uk/atlantib...book.html#http I *think*
- which also has a demo online).

The following chunk of code shows you which environemnt variable to
use to get the query string from 'GET' type requests.

if os.environ.get('REQUEST_METHOD','').lower()=='post ':
# do something with post data
thedata = fullparse(form)
from urllib import urlencode
txdata = urlencode(thedata) #
straightforward encode - need to test for/allow multipart form data
(file upload) and list types
elif os.environ.get('QUERY_STRING', '') and not
data['id']=='mjf-approx':
theurl = theurl + '?' + os.environ['QUERY_STRING']
txheaders = getheaders(txheaders) # proxy as many
of the headers as we can
don't worry about most of the code - but the following :
if os.environ.get('REQUEST_METHOD','').lower()=='get' :
querystring = os.environ.get('QUERY_STRING', '')

should do most of what you need...........
(os.environ is a dictionary containing the environment variables).

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantib...thonutils.html
Jul 18 '05 #2

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

Similar topics

1
by: Al Stoltz | last post by:
Greetings all. I've got a small web application (just a web interface to a MS-access database) and I recently upgraded ActiveState's python dist. from 2.2 to their latest (2.3.2 I think). In the...
0
by: Fred Murray | last post by:
Hi all, When uploading a file ("input type=file"), FieldStorage usually behaves correctly, but every once in a while (every couple days?), it will suddenly start causing internal server errors. ...
1
by: Austyn Bontrager | last post by:
Should cgi.FieldStorage examine the environment variable REDIRECT_REQUEST_METHOD before examining REQUEST_METHOD? I'm running Apache, and write my CGI scripts in Python. I have this in a...
1
by: Ames Andreas (MPA/DF) | last post by:
Hi, sorry for following-up to myself. Some remarks: 1) Please excuse the bogus original message. I wrote it a minute before I knocked off work and I promise to never do so again :-) 2)...
1
by: Ames Andreas (MPA/DF) | last post by:
Hi, I'm currently using Zope 2.7.2-0 which in turn uses cgi.FieldStorage from Python 2.3.4. FieldStorage can either build a 'list' or a 'file' to represent a request. Unfortunately it...
4
by: Derek Basch | last post by:
Given this FieldStorage object: FieldStorage(None, None, ) I am trying to cgi.urlencode the FieldStorage object to POST to another cgi script. The documentation for urlencode,...
0
by: John Salerno | last post by:
I'm trying to use a for loop with a FieldStorage object and I get the following error. Can you not treat it like a dictionary, or am I writing the for loop incorrectly? for item in form: print...
7
by: John Salerno | last post by:
If I want to get all the values that are entered into an HTML form and write them to a file, is there some way to handle them all at the same time, or must FieldStorage be indexed by each specific...
4
by: arorap | last post by:
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....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
1
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: 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.