I am using python's requests library to do a 'GET' from an API. here is part of my code :
payload = { 'topicIds':'128487',
'topicIds':'128485',
'topicIds': '242793',
'timePeriod':'10d', }
r= requests.get(url, params=payload, headers=headers)
According to the API documentation, we can assign multiple topicIds to one request like this: <url>topicId=123&topicId=246
when i try to set topicIds value as a list like this:
payload = { 'topicIds':['128487' , '242793'],
I get an error : {u'error': u'topicIds: has 2 terms, should be between 0 and 1'}
However when i run the code, i only get data from the last topicIds => 'topicIds': '242793' Am i writing the payload dictionary wrongly?
Thanks,
Try:
payload = {'topicIds[]': ['128487', '242793']}
r = requests.get(url, params=payload, headers=headers)
This is the most common way of defining arrays in query strings.
This would work as well
params = {'topicIds': ['128487', '128485', '242793'],
'timePeriod':'10d', }
r= requests.get(url, params=params)
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