Hi I am trying to read from a restful api
http://localhost:1010/productfamily?date=2015-08-28&list=abc,xyz
I am passing the values like this
url = 'http://localhost:1010/productfamily'
sdate = '2015-08-28'
plist = 'abc,xyz'
params = (('date', sdate ), ('list', plist))
requests.get(url, params)
I am not getting the wanted output. How do i pass a comma separated string in this way?
It works when i pass it like this
requests.get(url+?'date='+sdate'&lisy='plist)
To pass multiple values for the same key, pass in a dict with an iterable as its value
url = 'http://localhost:1010/productfamily'
params = {'sdate': '2015-08-28'}
params['plist'] = ('abc', 'xy')
requests.get(url, params)
EDIT:
The OP did ask for a comma separated value list, and as somewhatoff points out in the comments, this code produces multiple key=value parameters. That being said, the OP also states that they are "reading" from an API and issuing GET requests, indicating that this is not a service that they are creating. While there is NO spec for how to provide multiple values, my experience is that "most" server frameworks will accept this format for multiple values, and I've not seen the CSV format required "in the wild."
Wikipedia supports this position here: https://en.wikipedia.org/wiki/Query_string#Web_forms
Also see this answer for more information about the behavior of specific web servers: https://stackoverflow.com/a/1746566/4075135
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