jxn jxn - 1 year ago 91
HTTP Question

HTTP requests assign multiple values to a key in params

I am using python's requests library to do a 'GET' from an API. here is part of my code :

payload = { 'topicIds':'128487',
'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:

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?


Answer Source


payload = {'topicIds': ['128487', '242793']}
r = requests.get(url, params=payload, headers=headers)

This is the most common way of defining arrays in query strings.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download