user_78361084
user_78361084

Reputation: 3918

How do I get all the query string params from a request?

I have setup a simple gevent wsgi server that will not be exposed to the outside world. I am trying to get all the querystring params but can only get the first:

from gevent.pywsgi import WSGIServer
from cgi import parse_qs
...
...
d = parse_qs(env.get('QUERY_STRING',''))
print d

curl localhost:5000?goat=pig&piano=guitar prints:

{'goat': ['pig']}

How can I get all params:

{'goat': ['pig'], 'piano': ['guitar']}

Upvotes: 0

Views: 1093

Answers (1)

eatmeimadanish
eatmeimadanish

Reputation: 3907

You really should use a web framework like Bottle or Flask for this type of utility. The reason is that they are designed for this purpose, and handle things like request headers and JSON for you.

from bottle import route, request, response, template
@route('/forum')
def display_forum():
    forum_id = request.query.id
    page = request.query.page or '1'
    return template('Forum ID: {{id}} (page {{page}})', id=forum_id, page=page)

https://bottlepy.org/docs/dev/tutorial.html

Upvotes: 1

Related Questions