• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

how can i get POST GET variables from python?

how can i get POST GET variables from python?
0
ninjadude12
Asked:
ninjadude12
  • 4
  • 2
1 Solution
 
mish33Commented:
It depends on the framework you're using.
0
 
gelonidaCommented:
I agree with mish.
Without further details it's difficult to help you.

Did you write a plain cgi script?
Or a wsgi script?

or do you use a more complex framework?
0
 
ninjadude12Author Commented:
you dont need a framework to handle POST GET, ever herd of import cgi lol
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
gelonidaCommented:
Hi Ninjadude,

What we two experts tried to say is, that the way of accessing POST / GET  contents depends on what application / framework you are running.

We experts heard of
 import cgi (Refer for example to  http://www.experts-exchange.com/Q_27217214.html )

However this is not at all the correct response for somebody who's using other libraries / frameworks.
0
 
gelonidaCommented:
So for CGI scripts.

In order to get the GET vars you have to get the querystring (depends on the framework)
For cgi for example
query_string=os.environ['QUERY_STRING']

then you can  parse it:with

import urlparse
urlparse.parse_qs(query_string)
# example output: {'a': ['3'], 'b': ['4'], 'c': ['5']}

Please note, that unlike in PHP (if I remember correctly)  you always receive lists even for variables with only one value.
So perhaps you might consider to postprocess your list.

I very rarely used the cgi library, but please note, that up to my knowlege the default functions do not make a distinction  between POST and GET vars, so if you want to know what is a POST variable and what is a GET variable, then you have to do some more manual steps.

I think (but never tried) cgi.FieldStorage  just parsed both and combines the results.

0
 
ninjadude12Author Commented:
gelonida: who said i was using a framework?
0
 
gelonidaCommented:
Ninjadue,

You still did not explicitely say what you are using.
If you have a plain CGI script, then what is wrong with cgi.FieldStorage()


Do you want to make a distinction between the POST and GET variables or are you happy with a 'combined' answer.

0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now