Solved

how can i get POST GET variables from python?

Posted on 2011-09-12
9
259 Views
Last Modified: 2012-05-12
how can i get POST GET variables from python?
0
Comment
Question by:ninjadude12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
9 Comments
 
LVL 15

Expert Comment

by:mish33
ID: 36527625
It depends on the framework you're using.
0
 
LVL 17

Expert Comment

by:gelonida
ID: 36527718
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
ID: 36529469
you dont need a framework to handle POST GET, ever herd of import cgi lol
0
Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

 
LVL 17

Expert Comment

by:gelonida
ID: 36530381
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 17

Accepted Solution

by:
gelonida earned 500 total points
ID: 36530559
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
ID: 36530568
gelonida: who said i was using a framework?
0
 
LVL 17

Expert Comment

by:gelonida
ID: 36546131
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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…

688 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