0

I am trying to pass an argument to a python script via HTTP

e.g. http://www.domain.com/script.py?param=value

in some examples, I can see people using the cgi.FieldStorage() function to retrieve the GET parameters, but I cannot make it work

this is my code:

import cgi

print "Content-type: text/html\n"
arguments = cgi.FieldStorage()
print arguments

by making the http request either by the browser or via commandline with wget, this is the output I get for the object arguments:

FieldStorage(None, None, [])

which doesn't seem to store the GET parameter

what am I missing?

4
  • try with docs.python.org/2/library/cgitb.html Commented Apr 29, 2013 at 5:01
  • Change your print statement so that its correct: print "Content-Type: text/html\n\n" - and then check it again. Commented Apr 29, 2013 at 5:09
  • it still doesn't work Commented Apr 29, 2013 at 5:11
  • Instead of CGI which is ancient, basic, and slow, consider using something lightweight but higher-level, like web.py or flask. Commented Apr 29, 2013 at 16:05

1 Answer 1

1

in this way, it works!

import os, cgi

print "Content-Type: text/html\n"

query = os.environ.get('QUERY_STRING')
arguments = cgi.parse_qs(query) if query else {}
print arguments
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.