Solved

how can i get POST GET variables from python?

Posted on 2011-09-12
9
251 Views
Last Modified: 2012-05-12
how can i get POST GET variables from python?
0
Comment
Question by:ninjadude12
  • 4
  • 2
9 Comments
 
LVL 15

Expert Comment

by:mish33
Comment Utility
It depends on the framework you're using.
0
 
LVL 16

Expert Comment

by:gelonida
Comment Utility
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
 

Author Comment

by:ninjadude12
Comment Utility
you dont need a framework to handle POST GET, ever herd of import cgi lol
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 16

Expert Comment

by:gelonida
Comment Utility
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
 
LVL 16

Accepted Solution

by:
gelonida earned 500 total points
Comment Utility
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
 

Author Comment

by:ninjadude12
Comment Utility
gelonida: who said i was using a framework?
0
 
LVL 16

Expert Comment

by:gelonida
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now