I'm trying to make a simple REST api using the Python bottle app. I'm facing a problem in retrieving the GET variables from the request global object. Any suggestions how to retrieve this from the GET request?
They are stored in the request.query object.
http://bottlepy.org/docs/dev/tutorial.html#query-variables
It looks like you can also access them by treating the request.query attribute like a dictionary:
request.query['city'] So dict(request.query) would create a dictionary of all the query parameters.
As @mklauber notes, this will not work for multi-byte characters. It looks like the best method is:
my_dict = request.query.decode() or:
dict(request.query.decode()) to have a dict instead of a <bottle.FormsDict object at 0x000000000391B...> object.
If you want them all:
from urllib.parse import parse_qs dict = parse_qs(request.query_string) If you want one:
one = request.GET.get('one', '').strip()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With