python-requestsckan

POST request data containing list of dicts


I'm trying to call an API that wants a list of dicts for one value. I build a dict that looks similar to this:

dataset = { 
  'name': 'somename',
  'note': 'somenote',
  'extras': [{'first': 'entry'}]
}

I'm including this in my POST:

r = requests.post("URL_ENDPOINT", data=dataset, headers=headers)

Checking the actual dataset dictionary shows the list of dicts correctly.

{'name': 'somename', 'note': 'somenote', 'extras': [{'spatial': 'test'}]}

But checking the requests object, r.text:

 ... "extras": "first", "type": "dataset"}}, ...

It looks like the list of dicts is being munged in some fashion?


Solution

  • Try to inject json parameter instead of data

    r = requests.post("URL_ENDPOINT", json=dataset, headers=headers)