473,804 Members | 3,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CGI.FieldStorag e to HTML

Hi all

I do a CGI post, I am using CGI.FieldStorag e(), 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 2841
"Graeme Matthew" <gr************ @contrado.com.a u> wrote in message news:<41******* *************** *@per-qv1-newsreader-01.iinet.net.au >...
Hi all

I do a CGI post, I am using CGI.FieldStorag e(), 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(theda ta) #
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(txhe aders) # 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
4989
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 process, I broke some of my cgi scripts. A little troubleshooting reveals that the cgi.fieldstorage() method is not receiving any data at all when using an HTTP POST request in my HTML. If I change to a GET request, all is well.
0
1252
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. A look at the apache (v. 2.0.44 on Linux) error log shows "premature end of script headers" with no error messages from Python. After reloading the browser about 10 times in a row, it will suddenly start working again. Recently, when a series...
1
1827
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 /techdocs/.htaccess file: ErrorDocument 401 /forms/registration.cgi Require valid-user
1
1639
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) What I really wanted to know was: FieldStorage writes what it reads from the stream that is given to its constructor's fp (or sys.stdin by default) to a temporary file only _in some cases_. My
1
1952
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 overwrites __len__ such that it throws an exception when the request wasn't of type 'multipart', i.e. when it doesn't 'return' a list but a file. I'd consider this a bug because if you have an instance fs of FieldStorage you can't safely write
4
2123
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, http://docs.python.org/lib/module-urllib.html , says that urlencode takes a mapping object or a list of double tuples. I see that I could use cgi.parse_qs and cgi.parse_qsl to create these object types. Should I just use that or should I continue using...
0
1902
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 item # or print item.value
7
1588
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 field name?
4
4885
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. I can see the form data in sys.stdin but cgi.FieldStorage() returns an empty dictionary. Here's the code for the test script I am posting to - -- #!/usr/bin/python
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9134
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.