Getting HTTP GET arguments in Python Getting HTTP GET arguments in Python python python

Getting HTTP GET arguments in Python


cgi.FieldStorage() should do the trick for you... It returns a dictionary with key as the field and value as its value.

import cgiimport cgitb; cgitb.enable() # Optional; for debugging onlyprint "Content-Type: text/html"print ""arguments = cgi.FieldStorage()for i in arguments.keys(): print arguments[i].value


For GET requests I prefer cgi.parse(). It returns a simple dictionary of lists.

import cgiargs = cgi.parse()

For example, the query string ?key=secret&a=apple is parsed as:

{'key': ['secret'], 'a': ['apple']}